错误:找不到模块'html-webpack-plugin' - Webpack(React)

问题描述 投票:1回答:1

我尝试在此link之后使用webpack 4创建一个基本的React应用程序

直到安装“html-webpack-plugin”,我没有遇到任何错误。但是,一旦我运行命令“npm run start”,我就会收到以下错误:

**Error: Cannot find module 'html-webpack-plugin'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)**

我尝试使用以下两个线程通过全局和本地安装包来解决此问题,但它没有帮助。

error: cannot find module html-webpack-plugin

https://github.com/webpack/webpack-dev-server/issues/1330

请参阅下面的代码:

的package.json:

{
  "name": "react_website",
  "version": "1.0.0",
  "description": "Website using React and Webpack",
  "main": "index.js",
  "scripts": {
    "start": "webpack --mode development",
    "build": "webpack --mode production"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "html-webpack-plugin": "^3.2.0",
    "webpack": "^4.16.2",
    "webpack-cli": "^2.1.5"
  },
  "dependencies": {
    "react": "^16.4.1",
    "react-dom": "^16.4.1"
  }
}

webpack.config.js:

const HtmlWebPackPlugin = require("html-webpack-plugin");

module.exports = {
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      }
    ]
  },
  plugins: [
    new HtmlWebPackPlugin({
    template: "./src/index.html",
    filename: "./index.html"
  })
],
};

- .babelrc:

{
  "presets": ["env", "react"]
}
javascript reactjs webpack plugins html-webpack-plugin
1个回答
2
投票

使用此命令:

npm i --save-dev html-webpack-plugin
© www.soinside.com 2019 - 2024. All rights reserved.