webpack 打包运行react项目报错HtmlWebpackPlugin is not defined解决方案

运行yarn webpack打包项目报错HtmlWebpackPlugin is not defined,采坑过程升级webpack-cli版本、降低webpack版本都没有作用,我的项目中使用的是webpack5版本。


image.png

解决方案:
在webpack.config.js 文件中

const HtmlwebpackPlugin = require("html-webpack-plugin");
...
plugins: [
    new HtmlwebpackPlugin ({
      // template: "./index.html", //指定模板路径
      filename: "./dist/index.html", //指定文件名
    }),
  ],
改为
const htmlWebpackPlugin = require("html-webpack-plugin");
...
  plugins: [
    new htmlWebpackPlugin({
      // template: "./index.html", //指定模板路径
      filename: "./dist/index.html", //指定文件名
    }),
  ],

首先确保安装webpack、webpack-cli、html-webpack-plugin 才可启动成功

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容