pro-mern-stack
pro-mern-stack copied to clipboard
Webpack 4.5 - Error: webpack.optimize.CommonsChunkPlugin has been removed
Using webpack manually: testing webpack functionality returns an error:
node_modules/.bin/webpack static/App.js static/app.bundle.js /home/mark/pro-mern-stack/node_modules/webpack-cli/bin/webpack.js:242 throw err; ^
Error: webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.splitChunks instead.
at Object.get [as CommonsChunkPlugin] (/home/mark/pro-mern-stack/node_modules/webpack/lib/webpack.js:165:10)
at Object.
const webpack = require('webpack');
const path = require('path');
module.exports = {
entry: {
app: './src/App.jsx',
},
output: {
path: path.join(__dirname, './static'),
filename: "[name].bundle.js"
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all'
}
}
}
},
module: {
rules:[
{
test:/\.jsx$/,
use: {
loader: 'babel-loader',
query: {
presets: ['react','es2015']
}
}
},
]
},
};
try the above one as the error says try to use config.optimization.splitChunks instead i have added optimization property and seems to works for me.
when I write this, optimization: { splitChunks: { cacheGroups: { commons: { test: /[\/]node_modules[\/]/, name: 'vendor', chunks: 'all' } } } }, AN ERROR IS DISPLAYED C:\Users\hp\Desktop\web2.0-master\webpack.config.js:130 [0] }; SyntaxError: Unexpected token ;