question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnhandledPromiseRejectionWarning: TypeError: this.htmlWebpackPlugin.getHooks is not a function

See original GitHub issue

Is this a bug report? (Yes)

Currently hitting an issue with our environment using webpack 4 and the latest 6.0.5 package from create-react-app. Currently in the process we utilize react-dev-utils/InterpolateHtmlPlugin which has a method getHooks which seems to be leading to the following error:

(node:25316) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
(node:25316) UnhandledPromiseRejectionWarning: TypeError: this.htmlWebpackPlugin.getHooks is not a function

From what I can tell a commit 28 days ago may have re-introduced this old syntax, as https://github.com/facebook/create-react-app/blame/d55525651fb57e6ca6fb79c1d5c61601c129cbbd/packages/react-dev-utils/InterpolateHtmlPlugin.js this prior version seemed to use the new hook api

I’m not familiar enough with the codebase to suggest a fix, if just that file may have regressed or others.

Did you try recovering your dependencies?

Which terms did you search for in User Guide?

Environment

Steps to Reproduce

Coming Soon

Expected Behavior

Actual Behavior

Reproducible Demo

Coming Soon

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

10reactions
RichieRockcommented, Nov 22, 2018

I had the same issue. In case there’s someone else trying to upgrade to webpack 4 on a a react app, here’s some tips I had to do to make it working:

run npm install <plugin-name>@latest --save with all webpack plugins that you have run npm i html-webpack-plugin@next --saveto get the beta version of html-webpack-plugin (this works with webpack 4) Upgrade react-dev-utils and react if necessary Make sure new InterpolateHtmlPlugin(... is AFTER new HtmlWebpackPlugin({... in the plugins section of webpack.config file. Add the HtmlWebpackPlugin as parameter to InterpolateHtmlPlugin as stated by @kylealwyn and don’t forget the publicUrl in case you’re using it:

new InterpolateHtmlPlugin(HtmlWebpackPlugin, {
  PUBLIC_URL: publicUrl
}),

(Extra) Also since I’m using typescript, I had to update @types/webpack.

I hope this helps someone else 😃

9reactions
kylealwyncommented, Oct 17, 2018

https://github.com/facebook/create-react-app/pull/5031/files#diff-ea4f448ea185319313285123e7f97294R48

It looks like you now need to pass theHtmlWebpackPlugin object when adding the InterpolateHtmlPlugin

This fixed the issue for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack 4, this.htmlWebpackPlugin.getHooks is not a function
I'm migrating from webpack 3 to 4 and it is painfull ;). I'm getting this error: this.htmlWebpackPlugin.getHooks is not a function. I was...
Read more >
this.htmlWebpackPlugin.getHooks is not a function · Issue #1068
Having the same issue after installing alpha-2 and trying to build my app with webpack4 (and the config provided in react-create-app).
Read more >
How to use the html-webpack-plugin.getHooks function ... - Snyk
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >
html-webpack-plugin - npm
This is a webpack plugin that simplifies creation of HTML files to serve your webpack bundles. This is especially useful for webpack bundles ......
Read more >
解决webpack打包错误:this.htmlWebpackPlugin.getHooks is ...
this.htmlWebpackPlugin.getHooks is not a function 报错描述 经过一番搜索,在html-webpack-plugin的issue区看到了如下解决方法,亲测可用。
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found