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

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

Closed
alhazmy13 opened this issue Mar 4, 2018 · 17 comments

Comments

@alhazmy13
Copy link

Error Message & Stack Trace

(node:71449) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
(node:71449) DeprecationWarning: Tapable.apply is deprecated. Call apply on the plugin directly instead
TypeError: cb is not a function
    at compilation.plugin (/xxxxxx/.electron-vue/dev-runner.js:54:9)
    at Promise (eval at create (/xxxxx/node_modules/tapable/lib/HookCodeFactory.js:51:12), <anonymous>:11:16)
    at new Promise (<anonymous>)
    at AsyncSeriesWaterfallHook.eval [as promise] (eval at create (/xxxxxxx/node_modules/tapable/lib/HookCodeFactory.js:51:12), <anonymous>:4:8)
    at AsyncSeriesWaterfallHook.lazyCompileHook [as _promise] (/xxxxxx/node_modules/tapable/lib/Hook.js:35:21)
    at /xxxxx/node_modules/html-webpack-plugin/index.js:645:47
    at Promise.resolve.then.then.then.then.then.then.then.then.catch.then.then (/xxxxxx/node_modules/html-webpack-plugin/index.js:209:21)
    at <anonymous>

Config

module.exports = {
  entry: 'app.js',
  output: {
    path: 'dist',
    filename: 'index_bundle.js'
  },
  module: {
    rules: [
      ...
    ]
  }
  plugins: [
      new HtmlWebpackPlugin({
      filename: 'index.html',
      template: path.resolve(__dirname, '../src/index.ejs'),
      minify: {
        collapseWhitespace: true,
        removeAttributeQuotes: true,
        removeComments: true
      }
    }),
    ...
  ]
}

Html template file:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>togacat</title>
    <% if (htmlWebpackPlugin.options.nodeModules) { %>
      <script>
        require('module').globalPaths.push('<%= htmlWebpackPlugin.options.nodeModules.replace(/\\/g, '\\\\') %>')
      </script>
    <% } %>
  </head>
  <body>
    <div id="app"></div>
    <script>
      if (process.env.NODE_ENV !== 'development') window.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
    </script>

  </body>
</html>

Environment

Node.js v8.9.4
darwin 17.2.0
npm 5.6.0
webpack 4.1.0
html-webpack-plugin 3.0.4
@kagawagao
Copy link

I think this bug is caused by webpack upgrade, Plugin API has been changed, but some plugins are not yet compatible with webpack v4

@andriijas
Copy link

html-webpack-plugin seem to use the old plugin api in two places:

https://github.com/jantimon/html-webpack-plugin/blob/master/index.js#L65
https://github.com/jantimon/html-webpack-plugin/blob/master/index.js#L85

there should be a check like in other parts of that file (if (compiler.hooks) {compiler.hooks.emit.tap} else {compiler.plugin(...)}

@Gisleburt
Copy link

Duplicate of #874

@jantimon
Copy link
Owner

jantimon commented Mar 6, 2018

Should be fixed in 3.0.5.

@jantimon jantimon closed this as completed Mar 6, 2018
@Gisleburt
Copy link

Does fix deprecated warning, still doesn't load plugins in webpack 4. I've created #887 for that.

@kagawagao
Copy link

@jantimon
still here, call compiler.apply directly is also deprecated

@jantimon jantimon reopened this Mar 6, 2018
@jantimon
Copy link
Owner

jantimon commented Mar 6, 2018

@kagawagao thanks for the head up :)
what would be the new syntax for that?

@kagawagao
Copy link

in the stack trace

DeprecationWarning: Tapable.apply is deprecated. Call apply on the plugin directly instead

I guess it should be

new NodeTemplatePlugin(outputOptions).apply(childCompiler)

@jantimon
Copy link
Owner

jantimon commented Mar 6, 2018

Thanks @kagawagao - it's released in 3.0.6

@jantimon jantimon closed this as completed Mar 6, 2018
@theodorejb
Copy link

theodorejb commented Mar 6, 2018

I'm still getting the following warning in v3.0.6:

(node:10052) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead

Edit: maybe it's coming from the html-webpack-include-assets-plugin module instead of this one?

@alhazmy13
Copy link
Author

Yes, still I the issue exist with version 3.0.6

(node:93696) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
TypeError: cb is not a function
    at Promise (eval at create (/xxx/node_modules/tapable/lib/HookCodeFactory.js:51:12), <anonymous>:11:16)
    at new Promise (<anonymous>)
    at AsyncSeriesWaterfallHook.eval [as promise] (eval at create (/xxx/node_modules/tapable/lib/HookCodeFactory.js:51:12), <anonymous>:4:8)
    at AsyncSeriesWaterfallHook.lazyCompileHook [as _promise] (/xxx/node_modules/tapable/lib/Hook.js:35:21)
    at /xxx/node_modules/html-webpack-plugin/index.js:647:47
    at Promise.resolve.then.then.then.then.then.then.then.then.catch.then.then (/xxx/node_modules/html-webpack-plugin/index.js:211:21)
    at <anonymous>

@qazbnm456
Copy link

@theodorejb @alhazmy13 You may find out where the root cause is by setting process.traceDeprecation = true; in your webpack config or something. Then, you'll be able to see what line triggers the warning.

@alhazmy13 BTW, I noticed you're using electron-vue right? So, the warning actually comes from electron-vue's dev-runner.js. It's not html-webpack-plugin's fault. You can fix the code by conforming to the new API system, e.g.

compiler.hooks.compilation.tap('dev-runner', compilation => {
  compilation.hooks.htmlWebpackPluginAfterEmit.tapAsync('dev-runner', (data, cb) => {
    hotMiddleware.publish({ action: 'reload' })
    cb()
  })
}))

FYI, there're several lines of code need to be revised as well.

@alhazmy13
Copy link
Author

@qazbnm456 Thanks for your support, solved with your code.

@gaterking
Copy link

gaterking commented Apr 3, 2018

@jantimon I dont't think it has been fixed. In version 3.2.0, same error is showed.
cb is not a function …… at Promise (eval at create (*******\node_modules\html-webpack-plugin\node_modules\tapable\lib\HookCodeFactory.js:51:12), <anonymous>:11:16)

@jantimon
Copy link
Owner

jantimon commented Apr 3, 2018

@gaterking please create a new issue with a minimal reproduction example
and a stacktrace (please use process.traceDeprecation = true)

@gaterking
Copy link

gaterking commented Apr 8, 2018

@jantimon
It's my fault, I forget to update html-webpack-plugin-after-emit to webpack 4.

compiler.hooks.compilation.tap('html-webpack-plugin-after-emit', () => {  
        hotMiddleware.publish({  
              action: 'reload'  
        });  
     });  

In webpack 3 code:

 compiler.plugin('compilation', (compilation) => {
        compilation.plugin('html-webpack-plugin-after-emit', (data, cb) => {
            hotMiddleware.publish({
                action: 'reload'
            });
            // cb();
        });
    });

@lock
Copy link

lock bot commented May 31, 2018

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants