error: cannot find module html-webpack-plugin

元气小坏坏 提交于 2019-12-14 03:04:47

问题


I am in the process of working through a tutorial on Webpack, but after adding in HtmlWebpackPlugin and trying to run Webpack again, I get the following error:

Error: Cannot find module 'html-webpack-plugin'
    at Function.Module._resolveFilename (module.js:489:15)
...

I have tried installing the plugin both locally and globally and I get the error both times.

//webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: "./app.js", // bundle entry point
  output: {
    path: path.resolve(__dirname, 'dist'), // output directory
    filename: "[name].js" // name of generated bundle
  },
  plugins : [
    new HtmlWebpackPlugin({
      template: "index.html",
      inject: "body"
    })
  ]
};

//package.json
{
  "name": "hyperlocalnola",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "html-webpack-plugin": "^2.30.1"
  }
}

//app.js
var msg = require("./contents.js");
document.write(msg);

//contents.js
module.exports = "hello friend!";

Sorry about the wall of text for what is probably something very simple, but I cannot find what is causing this anywhere. Thanks in advance.

来源:https://stackoverflow.com/questions/46096799/error-cannot-find-module-html-webpack-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!