html-webpack-plugin icon indicating copy to clipboard operation
html-webpack-plugin copied to clipboard

html-webpack-plugin-before-html-processing error while working with webpack 4

Open duzy opened this issue 8 years ago • 9 comments

Prerequisites

  • WebPack 4.0.1

Description

Not working with webpack ^4.0.1

Error Message & Stack Trace

...
Creating an optimized production build...
Failed to compile.

Plugin could not be registered at 'html-webpack-plugin-before-html-processing'. Hook was not found.
BREAKING CHANGE: There need to exist a hook at 'this.hooks'. To create a compatiblity layer for this hook, hook into 'this._pluginCompat'.


npm ERR! code ELIFECYCLE
npm ERR! errno 1
...

Config

Copy the relevant section from webpack.config.js:

    "webpack": "^4.0.1",
    "webpack-cli": "^2.0.10",

Environment

Ubuntu

duzy avatar Mar 03 '18 04:03 duzy

Webpack 4 changed the way how plugins communicate. The plugin which is using the "html-webpack-plugin-before-html-processing" has to be upgraded to webpack 4.x

jantimon avatar Mar 06 '18 13:03 jantimon

I'm having the same problem - and it looks like you're saying it isn't this plugin that's actually the problem? Any idea how to find out what the offending plugin is?

TomFoyster avatar Mar 07 '18 12:03 TomFoyster

@duzy @TomFoyster if you started with create-react-app, looks like https://github.com/facebook/create-react-app/tree/next/packages/react-dev-utils#new-interpolatehtmlpluginreplacements-keystring-string is potentially the culprit

here's fix in CRA Webpack 4 PR: https://github.com/facebook/create-react-app/pull/4077/files#diff-3b55301108483c3bb5289672dd9caa59

kylealwyn avatar Mar 07 '18 21:03 kylealwyn

@kylealwyn You're exactly right. We're now waiting for CRA to update to support WP4, and then we're going to have to recreate our App, which should be fun.

We've some really good gains with WP4 though in one of our component libraries though, so it'll be worth it.

Thanks for your help :)

TomFoyster avatar Mar 08 '18 12:03 TomFoyster

Following the PR created, Would the problem below be covered in this PR?

Plugin could not be registered at 'html-webpack-plugin-before-html-processing'. Hook was not found.
BREAKING CHANGE: There need to exist a hook at 'this.hooks'. To create a compatiblity layer for this hook, hook into 'this._pluginCompat'.

tiarebalbi avatar Mar 21 '18 05:03 tiarebalbi

Can some one please, view this PR? @sokra @pducks32

RiCoTeRoX avatar Apr 27 '18 22:04 RiCoTeRoX

If you ejected from create-react-app and are getting this error upon yarn build, make sure the InterpolateHtmlPlugin line comes after the HtmlWebpackPlugin line in your webpack config file(s):

module.exports = {
  //...
  plugins: [
    new HtmlWebpackPlugin({
      // ...
    }),
    new InterpolateHtmlPlugin(env.raw),
    //..
  ]
}

b0o avatar Apr 28 '18 04:04 b0o

If the order is switched around are the environment variables still used by HtmlWebpackPlugin?

MattyBalaam avatar May 18 '18 11:05 MattyBalaam

@MattyBalaam not in my case...

dkocich avatar Jun 11 '18 12:06 dkocich