Html-webpack-plugin: ReferenceError: HtmlWebpackPlugin is not defined

Created on 1 Jun 2020  路  2Comments  路  Source: jantimon/html-webpack-plugin

Expected behaviour

build using HtmlWebpackPlugin succeeds

Current behaviour

pogilvie: (master):~/Projects/learning/wp-> npm run build

> [email protected] build /Users/pogilvie/Projects/Learning/wp
> webpack

/Users/pogilvie/Projects/Learning/wp/node_modules/webpack-cli/bin/cli.js:93
                throw err;
                ^


ReferenceError: HtmlWebpackPlugin is not defined
    at Object.<anonymous> (/Users/pogilvie/Projects/Learning/wp/w

Environment

Tell us which operating system you are using, as well as which versions of Node.js, npm, webpack, and html-webpack-plugin. Run the following to get it quickly:

Node.js v10.13.0
darwin 19.5.0
[email protected]
npm ls html-webpack-plugin
[email protected]

Config

module.exports = {
  entry: {
    app: './src/index.js',
    print: './src/print.js'
  },
  plugins: [
    new HtmlWebpackPlugin()
  ],
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
};

Copy your template file if it is part of this issue:

<!doctype html>
<html>
  <head>
    <title>Output Management</title>
    <script src="./print.bundle.js"></script>
  </head>
  <body>
    <script src="./app.bundle.js"></script>
  </body>
</html>

Relevant Links

Additional context

I'm following the webpack tutorial and hit this.

https://webpack.js.org/guides/output-management/

I'm not sure how to debug this. thanks!

Most helpful comment

Did you require the plugin in the config file?

const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  ...,
  plugins: [
    new HtmlWebpackPlugin(),
    ...,
  ],
  ...,
};

All 2 comments

Did you require the plugin in the config file?

const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  ...,
  plugins: [
    new HtmlWebpackPlugin(),
    ...,
  ],
  ...,
};

Sigh thank you for taking the time to help a newbie out! That was it.

Was this page helpful?
0 / 5 - 0 ratings