webpack因HtmlWebpackPlugin报TypeError The compilation argument must be an instance of Compilation解决办法
· 预计阅读时间:1 分钟
摘要
webpack因HtmlWebpackPlugin报TypeError: The 'compilation' argument must be an instance of Compilation
报错信息#
运行webpack命令打包时报错,错误信息如下
TypeError: The 'compilation' argument must be an instance of Compilation情景分析#
安装并在webpack.config.js中配置了HtmlWebpackPlugin插件后打包报错,即分析为HtmlWebpackPlugin插件所导致的问题,此时我使用的webpack是版本5而HtmlWebpackPlugin使用的是4
报错原因#
因为webpack5与 html-webpack-plugin4的兼容问题
解决办法#
方式1:将weback换成4.x.x的版本#
npm install webpack@4.44.2npm install html-webpack-plugin@4 --save-dev方式2:html-webpack-plugin升级为5.x.x版本#
npm install html-webpack-plugin@5 --save-dev