Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'tapAsync' of undefined #44

Closed
nim-f opened this issue Jun 13, 2019 · 14 comments
Closed

Cannot read property 'tapAsync' of undefined #44

nim-f opened this issue Jun 13, 2019 · 14 comments

Comments

@nim-f
Copy link

nim-f commented Jun 13, 2019

Plugin doesn't work with ejected create-react-app, webpack version is 4.29.6

@numical
Copy link
Owner

numical commented Jun 17, 2019

Hi,
Can I get a bit more detail?
package.json
webpack.config
stack trace
etc.

Also does it work before ejection?

@nim-f
Copy link
Author

nim-f commented Jun 18, 2019

yes it worked before ejection, it was default CRA

gist with package.json and webpack config https://gist.github.com/nim-f/69a2d0ffd6cbb05ff8bc9ba197455c44

full error:

yarn run v1.13.0
$ node scripts/build.js
Creating an optimized production build...
Failed to compile.

Cannot read property 'tapAsync' of undefined


TypeError: Cannot read property 'tapAsync' of undefined
    at StyleExtHtmlWebpackPlugin.wirePluginEvent (/Users/nimf/test-w/node_modules/style-ext-html-webpack-plugin/lib/plugin.js:114:32)
    at StyleExtHtmlWebpackPlugin.compilationCallback (/Users/nimf/test-w/node_modules/style-ext-html-webpack-plugin/lib/plugin.js:56:5)
    at SyncHook.eval [as call] (eval at create (/Users/nimf/test-w/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
    at SyncHook.lazyCompileHook (/Users/nimf/test-w/node_modules/tapable/lib/Hook.js:154:20)
    at Compiler.newCompilation (/Users/nimf/test-w/node_modules/webpack/lib/Compiler.js:581:26)
    at hooks.beforeCompile.callAsync.err (/Users/nimf/test-w/node_modules/webpack/lib/Compiler.js:617:29)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/nimf/test-w/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/nimf/test-w/node_modules/tapable/lib/Hook.js:154:20)
    at Compiler.compile (/Users/nimf/test-w/node_modules/webpack/lib/Compiler.js:612:28)
    at readRecords.err (/Users/nimf/test-w/node_modules/webpack/lib/Compiler.js:284:11)
    at Compiler.readRecords (/Users/nimf/test-w/node_modules/webpack/lib/Compiler.js:479:11)
    at hooks.run.callAsync.err (/Users/nimf/test-w/node_modules/webpack/lib/Compiler.js:281:10)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/nimf/test-w/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/nimf/test-w/node_modules/tapable/lib/Hook.js:154:20)
    at hooks.beforeRun.callAsync.err (/Users/nimf/test-w/node_modules/webpack/lib/Compiler.js:278:19)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/nimf/test-w/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@Kupstas
Copy link

Kupstas commented Jun 21, 2019

Any news?

@Venefilyn
Copy link

Getting the same error, also with ejected CRA. Very similar to the config nim-f posted

@nim-f
Copy link
Author

nim-f commented Jun 21, 2019

I had same kind of problem with another plugin, then replaced compilation.hooks.htmlWebpackPluginAlterAssetTags.tap with HtmlWebpackPlugin.getHooks(e).alterAssetTags.tap and it worked.

Seems api of HtmlWebpackPlugin changed and plugins need to be updated as well

@Venefilyn
Copy link

Workaround might be to use an older version of HtmlWebpackPlugin then. Will try tomorrow and report back (if I remember)

@Venefilyn
Copy link

Venefilyn commented Jun 24, 2019

Could not downgrade HtmlWebpackPlugin due to dependencies. Though looking at the source and changing stuff I encountered this

Plugin could not be registered at 'htmlWebpackPluginBeforeHtmlProcessing'. Hook was not found.
BREAKING CHANGE: There need to exist a hook at 'this.hooks'. To create a compatibility layer for this hook, hook into 'this._pluginCompat'.

Which happened when I changed:

-if (compilation.hooks) {
+if (compilation.hooks && compilation.hooks[event]) {
  debug('MikeE', event);
  debug('MikeE', compilation.hooks);
  compilation.hooks[event].tapAsync('StyleExtHtmlWebpackPlugin', wrappedFn);
} else {
  compilation.plugin(event, wrappedFn);
}

Though I've yet to figure out anything further

@Venefilyn
Copy link

Tried changing it around

// HtmlWebpackPlugin 4.x and later
const htmlWebpackHookEvents = {
  htmlWebpackPluginBeforeHtmlProcessing: 'beforeAssetTagGeneration',
  htmlWebpackPluginAlterAssetTags: 'alterAssetTags',
  htmlWebpackPluginAfterHtmlProcessing: 'afterTemplateExecution'
}

//...

if (compilation.hooks) {
  debug('MikeE', event);
  debug('MikeE', compilation.hooks);

  if (compilation.hooks[event]) {
    compilation.hooks[event].tapAsync('StyleExtHtmlWebpackPlugin', wrappedFn);
  }
  else {
    // deals with HtmlWebpackPlugin 4
    var HtmlWebpackPlugin = require('html-webpack-plugin');
    var hooks = HtmlWebpackPlugin.getHooks(compilation);
    hooks[htmlWebpackHookEvents[event]].tapAsync('StyleExtHtmlWebpackPlugin', wrappedFn);
  }
}

Yet now I'm encountering

./node_modules/@patternfly/react-styles/css/components/OptionsMenu/options-menu.css
TypeError: this[MODULE_TYPE] is not a function

And although that TypeError is not part of this library, I'm not sure if it is causing the issue

@Venefilyn
Copy link

The code above does work, tried it without MiniCssExtractPlugin and it encountered no issues.

Though I'm getting the TypeError issue together with MiniCssExtractPlugin (formerly ExtractTextWebpackPlugin). I'm unsure as to why

@numical
Copy link
Owner

numical commented Jul 4, 2019

Hi - working on this.
I now have successfully breaking tests (!) for HtmlWebpackPlugin v4 on branch feature/html-webpack-plugin-4-support and getting these fixed based on @SpyTec's suggested PR.

@numical
Copy link
Owner

numical commented Jul 4, 2019

That was easier than expected.
v4.1.0 now support HtmlWebpackPlugin v4.x. and will no longer encounter this error.
Thanks @SpyTec!

@JZO001
Copy link

JZO001 commented Mar 28, 2020

Looks like the issue is still exist :( I just copy paste the example code into my webpack config file, latest version installed from this plugin and when I run, I get tapAsync issue again. Anybody can help me please?

@sayjeyhi
Copy link

sayjeyhi commented Apr 24, 2020

I am facing this issue too, any updates?

beforeGenerationHook.tapPromise('AddAssetHtmlPlugin', htmlPluginData =>
^

TypeError: Cannot read property 'tapPromise' of undefined
at compiler.hooks.compilation.tap.compilation (/JEY/node_modules/add-asset-html-webpack-plugin/lib/index.js:119:28)
at SyncHook.eval [as call] (eval at create (/JEY/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:15:1)
at SyncHook.lazyCompileHook (/JEY/node_modules/tapable/lib/Hook.js:154:20)
at Compiler.newCompilation (/JEY/node_modules/webpack/lib/Compiler.js:631:26)
at hooks.beforeCompile.callAsync.err (/JEY/node_modules/webpack/lib/Compiler.js:667:29)

@MikeMitterer
Copy link

The only solution I found was to downgrade to 3.2.0

The same here:

/Volumes/DevLocal/DevTypeScript/Production/mobiad/auth/node_modules/html-beautify-webpack-plugin/index.js:46
            compilation.hooks.htmlWebpackPluginAfterHtmlProcessing.tapAsync('HtmlBeautifyPlugin', (htmlPluginData, callback) => {
                                                                   ^

TypeError: Cannot read property 'tapAsync' of undefined
    at /Volumes/DevLocal/DevTypeScript/Production/mobiad/auth/node_modules/html-beautify-webpack-plugin/index.js:46:68
    at SyncHook.eval [as call] (eval at create (/Volumes/DevLocal/DevTypeScript/Production/mobiad/auth/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:9:1)
    at SyncHook.lazyCompileHook (/Volumes/DevLocal/DevTypeScript/Production/mobiad/auth/node_modules/tapable/lib/Hook.js:154:20)
    at Compiler.newCompilation (/Volumes/DevLocal/DevTypeScript/Production/mobiad/auth/node_modules/webpack/lib/Compiler.js:631:26)
    at /Volumes/DevLocal/DevTypeScript/Production/mobiad/auth/node_modules/webpack/lib/Compiler.js:667:29
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Volumes/DevLocal/DevTypeScript/Production/mobiad/auth/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Volumes/DevLocal/DevTypeScript/Production/mobiad/auth/node_modules/tapable/lib/Hook.js:154:20)
    at Compiler.compile (/Volumes/DevLocal/DevTypeScript/Production/mobiad/auth/node_modules/webpack/lib/Compiler.js:662:28)
    at /Volumes/DevLocal/DevTypeScript/Production/mobiad/auth/node_modules/webpack/lib/Watching.js:77:18
    at _next0 (eval at create (/Volumes/DevLocal/DevTypeScript/Production/mobiad/auth/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:25:1)
    at eval (eval at create (/Volumes/DevLocal/DevTypeScript/Production/mobiad/auth/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:34:1)
    at LiveReloadPlugin.serverStarted (/Volumes/DevLocal/DevTypeScript/Production/mobiad/auth/node_modules/webpack-livereload-plugin/index.js:89:9)
    at Object.onceWrapper (events.js:420:28)
    at Server.emit (events.js:314:20)
    at emitListeningNT (net.js:1350:10)
    at processTicksAndRejections (internal/process/task_queues.js:79:21)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants