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

Webpack 4: compilation.mainTemplate.applyPluginsWaterfall is not a function

Open devthejo opened this issue 8 years ago • 32 comments

Description

Webpack 4 support: compilation.mainTemplate.applyPluginsWaterfall is not a function

Error Message & Stack Trace

compilation.mainTemplate.applyPluginsWaterfall is not a function
    at /var/www/myproject/node_modules/html-webpack-plugin/lib/compiler.js:81:

devthejo avatar Jan 26 '18 10:01 devthejo

There is a PR for Webpack 4 support: https://github.com/jantimon/html-webpack-plugin/pull/823

Here is the source branch: https://github.com/Graham42/html-webpack-plugin/tree/feat/webpack-4

The author warns about chunk-related issues, but in my starter Webpack 4 beta setup, it is working.

jbruni avatar Jan 28 '18 19:01 jbruni

@jbruni I get an error from the branch. compilation.hooks.htmlWebpackPluginAlterChunks = new SyncWaterfallHook(['chunks', 'objectWithPluginRef']); TypeError: SyncWaterfallHook is not a constructor

gaterking avatar Feb 06 '18 10:02 gaterking

Actually I got a fix for the SyncWaterfallHook error, this seems to be due to different webpack plugin using different versions of Tapable.

But if you install the latest Tapable yourself in your package.json like this

"tapable": "1.0.0-beta.5",

Everything seems to work...

Right now this is my package.json setup to get Webpack4 up and running, I hope it helps

    "html-webpack-plugin": "webpack-contrib/html-webpack-plugin",
    "tapable": "1.0.0-beta.5",
    "webpack": "^4.0.0-beta.1",
    "webpack-cli": "^2.0.6",
    "webpack-dev-server": "^3.0.0-beta.1",

stevenfitzpatrick avatar Feb 17 '18 14:02 stevenfitzpatrick

@stevenfitzpatrick is your fix still working for you? I tried but it does not seem to work. Will this be fixed soon in master? I mean, webpack@4 compatibility.

I see a long list like:

ERROR in   TypeError: __webpack_require__(...) is not a function
  
  - es6.regexp.replace.js?:2 eval
    [.]/[core-js]/modules/es6.regexp.replace.js?:2:90
  
  - index.html:339 Object../node_modules/core-js/modules/es6.regexp.replace.js
    /Users/damz/Desktop/yarsk/app/index.html:339:1

My index.html is 12 lines long, so I don't know what index.html:339 is. Removing html-webpack-plugin works fine, but I have no hijacked html xD

damianobarbati avatar Feb 21 '18 11:02 damianobarbati

@jbruni would you share your working starter kit for anyone having this at the moment?

damianobarbati avatar Feb 21 '18 14:02 damianobarbati

@damianobarbati - There is nothing special to share... I've only used the fork in place of the regular plugin. I was not using chunks, the project had few dependencies... But I discontinued it. It was kind of a test/play little exercise.

jbruni avatar Feb 23 '18 23:02 jbruni

@jbruni sorry for the noise, the error thrown by html-plugin was related to babel. It's very weird anyway: I wrote a simple plugin on my own to put the assets into the html and exclude html-webpack-plugin possible errors. It worked flawlessly and the error was instead fired into console at runtime (it's not fired by webpack): how did it end up into the html file? 🤨

damianobarbati avatar Feb 23 '18 23:02 damianobarbati

Hey, what the status, any news? new HtmlWebpackPlugin() still doesn't work for me
I'm suing config

   "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.1",
    "html-webpack-plugin": "^2.30.1",
    "webpack": "^4.0.0",
    "webpack-cli": "^2.0.9"
  }

And got

/node_modules/html-webpack-plugin/lib/compiler.js:81
        var outputName = compilation.mainTemplate.applyPluginsWaterfall('asset-path', outputOptions.filename, {
                                                  ^

TypeError: compilation.mainTemplate.applyPluginsWaterfall is not a function

iliatcymbal avatar Feb 25 '18 16:02 iliatcymbal

@iliatcymbal Use yarn add webpack-contrib/html-webpack-plugin -D, a fork maintained by WebPack until the maintaner of this plugin is able to resolve this, and you'll be set. I did it this morning and it works flawlessly.

TomasHubelbauer avatar Feb 25 '18 16:02 TomasHubelbauer

@TomasHubelbauer, that works for me, thank you! How did you get this?)

iliatcymbal avatar Feb 25 '18 17:02 iliatcymbal

@TomasHubelbauer I updated to webpack-contrib/html-webpack-contrib but still have an error:

compilation.hooks.htmlWebpackPluginAlterChunks = new SyncWaterfallHook(['chunks', 'objectWithPluginRef']);
                                                       ^

TypeError: SyncWaterfallHook is not a constructor
    at /node_modules/html-webpack-plugin/index.js:50:56

Any idea why? Thank you

francoisromain avatar Feb 25 '18 18:02 francoisromain

@francoisromain Maybe rm -rf node_modules/ && npm install?

kutsan avatar Feb 25 '18 18:02 kutsan

@kutsan I did that already… Maybe is it related to this: https://github.com/webpack-contrib/html-webpack-plugin/issues/13 ?

francoisromain avatar Feb 25 '18 18:02 francoisromain

This https://github.com/webpack-contrib/html-webpack-plugin/commit/6319451c00494ec32fea9176bfdcb7528185ab35 fixed it for me. Thanks.

francoisromain avatar Feb 26 '18 10:02 francoisromain

Solution is to run yarn add webpack-contrib/html-webpack-plugin -D

yarn can fix the dependencies according to packages.

virkse avatar Feb 28 '18 07:02 virkse

html-webpack-plugin 3.0.0 seems to be out...and everything just works : )

stevenfitzpatrick avatar Feb 28 '18 21:02 stevenfitzpatrick

Still getting a deprecation warning with html-webpack-plugin 3.0.0+

DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead

Jarch09 avatar Mar 05 '18 01:03 Jarch09

@damianobarbati i just meet the same error when i use webpack4 , do you resolve this case ?

ERROR in   TypeError: __webpack_require__(...) is not a function
  
  - es6.regexp.replace.js?:2 eval
    [.]/[core-js]/modules/es6.regexp.replace.js?:2:90
  
  - index.html:339 Object../node_modules/core-js/modules/es6.regexp.replace.js
    /Users/damz/Desktop/yarsk/app/index.html:339:1

Ghostdar avatar Mar 14 '18 15:03 Ghostdar

Still getting this error too in a react native project with styleguidist. I'm using this configuration for a project of mine: https://github.com/styleguidist/react-styleguidist/tree/master/examples/react-native

This is the error:

(node:18009) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
(node:18009) DeprecationWarning: Tapable.apply is deprecated. Call apply on the plugin directly instead

TypeError: compilation.mainTemplate.applyPluginsWaterfall is not a function
TypeError: compilation.mainTemplate.applyPluginsWaterfall is not a function

giacomocerquone avatar Mar 15 '18 10:03 giacomocerquone

i met 2 problems and i resolved them by @stevenfitzpatrick but then i met this problem:

ERROR in ./main.js
Module build failed: TypeError: Cannot read property 'babel' of undefined
    at Object.module.exports (/Users/shenxin/playground/webpack2/node_modules/babel-loader/lib/index.js:103:36)
 @ multi ../node_modules/webpack-dev-server/client?http://localhost:8080 webpack/hot/dev-server react-hot-loader/patch ./main.js webpack-dev-server/client?http://localhost:8080 webpack/hot/only-dev-server

I fixed the problem by installing the latest version of my packages.

Silvia813 avatar Mar 16 '18 07:03 Silvia813