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 when use @next #1049

Closed
jiangjiu opened this issue Sep 17, 2018 · 5 comments
Closed

Cannot read property 'tapAsync' of undefined when use @next #1049

jiangjiu opened this issue Sep 17, 2018 · 5 comments
Labels

Comments

@jiangjiu
Copy link

Expected behaviour

no errors.

Current behaviour

Cannot read property 'tapAsync' of undefined

Environment

Tell us which operating system you are using, as well as which versions of Node.js, npm, webpack, and html-webpack-plugin. Run the following to get it quickly:

node 10.8.0
npm 6.2
 webpack 4.19.0
 html-webpack-plugin ^4.0.0-alpha.2

Config

Copy the minimal webpack.config.js to produce this issue:

module.exports = {
    entry: './index.js',
    mode:'development',
    plugins: [
        new htmlWebpackPlugin(),
        new htmlWebpackHarddiskPlugin()
    ]
};

Copy your template file if it is part of this issue:

<!DOCTYPE html>
<html>
    <head>
        <title>My App</title>
    </head>
    <body>
    </body>
</html>

Relevant Links

no needs.

Additional contex

while i use html-webpack-plugin@3.2.0, no errors.

when I use @next, compilation.hooks.has no html-balabal hooks,

please tell me how to fix it, thx U~

@jiangjiu
Copy link
Author

html-webpack-plugin@4.0.0-alpha is no errors too.

@zenoven
Copy link

zenoven commented Sep 17, 2018

same issue working with HtmlWebpackIncludeAssetsPlugin, and I'm using the latest alpha2 version

HtmlWebpackIncludeAssetsPlugin instance is after multiple instances of HTMLWebpackPlugin like below

glob.sync('views/**/*.html', {cwd: srcPath})
  .forEach( (filePath) => {
    let chunk = filePath.slice(0, path.extname(filePath).length * -1)

    plugins.push(new HTMLWebpackPlugin({
      filename: filePath,
      template: filePath,
      minify: false,
      inject: false,
      chunks: entry[chunk] ? [ chunk ] : []
    }))
  })

plugins.push(new HtmlWebpackIncludeAssetsPlugin({
  assets: [
    {
      path: 'client/',
      globPath: distPath,
      glob: 'vendors*.js'
    }
  ],
  append: false
}),)

@edmorley
Copy link
Contributor

edmorley commented Sep 20, 2018

The reason for this is that the hook names are changed in html-webpack-plugin 4.x, so plugins will need to be updated to support it.

It looks like html-webpack-harddisk-plugin will need updating here:
https://github.com/jantimon/html-webpack-harddisk-plugin/blob/0c7c75b9aec5201782660b26f33f3fb23e76f5fc/index.js#L17

same issue working with HtmlWebpackIncludeAssetsPlugin, and I'm using the latest alpha2 version

This was fixed in jharris4/html-webpack-tags-plugin#34 and has now been released in v1.05 of that plugin.

@agulado
Copy link

agulado commented Nov 7, 2018

hi, @edmorley
i'm sorry for my english.
i have same issue: Cannot read property 'tapAsync' of undefined when use @next | @3.2.0 | @4.0.0-alpha
webpack@4.17.1
use react-create-app create my app and no eject.

the problem maybe come from html-webpack-inline-source-plugin, and i can't solve it.
help me please.

// webpack.js#L35
if (options.plugins && Array.isArray(options.plugins)) {
            for (const plugin of options.plugins) {
                console.log(plugin); // result: HtmlWebpackInlineSourcePlugin {}
                plugin.apply(compiler);
            }
        }
// html-webpack-inline-source-plugin/index.js#L12
HtmlWebpackInlineSourcePlugin.prototype.apply = function (compiler) {
  var self = this;

  // Hook into the html-webpack-plugin processing

  (compiler.hooks
    ? compiler.hooks.compilation.tap.bind(compiler.hooks.compilation, 'html-webpack-inline-source-plugin')
    : compiler.plugin.bind(compiler, 'compilation'))(function (compilation) {
      console.log(compilation.hooks.htmlWebpackPluginAlterAssetTags); // ----- undefined  -----
      (compilation.hooks
      ? compilation.hooks.htmlWebpackPluginAlterAssetTags.tapAsync.bind(compilation.hooks.htmlWebpackPluginAlterAssetTags, 'html-webpack-inline-source-plugin')
      : compilation.plugin.bind(compilation, 'html-webpack-plugin-alter-asset-tags'))(function (htmlPluginData, callback) {
        if (!htmlPluginData.plugin.options.inlineSource) {
          return callback(null, htmlPluginData);
        }

        var regexStr = htmlPluginData.plugin.options.inlineSource;

        var result = self.processTags(compilation, regexStr, htmlPluginData);

        callback(null, result);
      });
    });
};

now, i use this method to ignore the error:

// webpack#L35
if (options.plugins && Array.isArray(options.plugins)) {
            for (const plugin of options.plugins) {

                // so stupid, hahaha
                if (JSON.stringify(plugin) === '{}')
                    continue;

                plugin.apply(compiler);
            }
        }

THX~

@stale
Copy link

stale bot commented May 6, 2019

This issue had no activity for at least half a year. It's subject to automatic issue closing if there is no activity in the next 15 days.

@stale stale bot added the wontfix label May 6, 2019
@stale stale bot closed this as completed May 21, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants