Error: webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.splitChunks instead.
解决方法:
我使用淘宝镜像cnpm install安装依赖成功后执行npm run build时报错:
Error: webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.splitChunks instead.
我发现在cnpm install 时有警告:requires a peer of webpack@^3.1.0 but webpack@4.41.2 was installed,可以看出webpack版本有問題,就是我項目要求使用webpack@^3.1.0但下载的是webpack@4.41.2
所以我先把所有依赖删除:
rm -rf node_modules
rm -rf package-lock.json
npm cache clear --force
cpm cache clear --force
本文解决了一个常见的Webpack配置问题,即CommonsChunkPlugin被移除,应使用optimization.splitChunks代替。详细介绍了如何调整项目配置以匹配正确的Webpack版本,包括清理缓存、删除依赖和重新安装。

3万+

被折叠的 条评论
为什么被折叠?



