Error with newer versions of node/webpack
Opened this issue · 0 comments
osotnikov commented
Recently I've upgraded my angular, typescript, webpack and node. I assume the issue is node but I'm not sure. Something broke this plugin so I'm getting this error:
An unhandled exception occurred: Cannot add property main.js, object is not extensible
the fix is to make a copy of "assets" array because the original object is not extensible:
`module.exports = class Rename {
constructor(options) {
this.options = { ...options };
}
apply(compiler) {
compiler.hooks.emit.tap('Rename.emit', compilation => {
const { assets } = compilation;
const { originNameReg, targetName } = this.options;
const originFiles = Object.keys(assets).filter(fileName =>
new RegExp(originNameReg).test(fileName)
);
originFiles.forEach(fileName => {
let assetsCopy = Object.assign([], assets);
assetsCopy[fileName.replace(originNameReg, targetName)] = assetsCopy[fileName];
delete assetsCopy[fileName];
});
});
}
};`