我们在webpack.config.js使用HtmlWebpackPlugin时,webpack打包会碰见TypeError: The ‘compilation’ argument must be an instance of Compilation弹错,并且无法打包
经过资料查询,大概率和版本有关系,这里给一个全套得解决方案:
首先我们要先写在原先的webpack:
npm uninstall webpack -g
然后我们需要重新安装指定版本webpack,这里引用了百度解决方案上的版本:百度解决方案
npm install webpack@4.44.2 -g
再安装下html-webpack-plugin
npm i --save-dev html-webpack-plugin
在webpack.config.js中:
const {resolve} = require('path')
const HtmlWebpackPlugin = require(require.resolve('html-webpack-plugin', { paths: [process.cwd()] }));
看的其他资料大概5.xx+ 版本好像都不能行,如果有更好的解决方案欢迎分享