0

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.

2
  • Do you see it in your node_modules folder? Commented Sep 7, 2017 at 19:26
  • Ah. Thank you, that must be it. I cannot find it in the node_modules folder with the rest of the modules. I am confused as to why it isn't there, however, since I have done npm install html-webpack-plugin --dev-save, as well as -g ..and the message I get is "updated 1 package..." but it is not there when I check the folders. Commented Sep 8, 2017 at 12:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.