npm run build error for html-webpack-plugin

Webpack 4 has some deprecation changes and an author of the html-webpack-plugin hasn't changed the code for the new requirements and that's why this plugin doesn't work with the new webpack 4 version.

The core webpack team forked this plugin till the author change the initial code and theirs fork available by this package contrib/html-webpack-plugin

So you should install this fork instead the original one.

You can do it by simply installing from npm or yarn eg

npm i -D html-webpack-plugin@webpack-contrib/html-webpack-plugin

or with yarn

yarn add -D html-webpack-plugin@webpack-contrib/html-webpack-plugin

There are no requirement to use exactly yarn =) you can do it via npm as well

More detailed info: Webpack 4 release announce


I fixed this issue by installing the beta version of HTML Webpack Plugin.

npm i --save-dev html-webpack-plugin@next

For those who are looking for an updated solution to this question, the module webpack-contrib/html-webpack-plugin does not exist anymore. For more details you may look up at the discussion here. The solution,npm install html-webpack-plugin --save-dev works. If this throws a run time error described in the OP's question, you can try installing a version specific module, npm i [email protected]. Hopefully this should work for you, as it did for me.