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

Webpack 4 outputs deprecation warnings #154

Closed
ai opened this issue Feb 21, 2018 · 14 comments
Closed

Webpack 4 outputs deprecation warnings #154

ai opened this issue Feb 21, 2018 · 14 comments

Comments

@ai
Copy link
Contributor

ai commented Feb 21, 2018

Issue description

Using webpack-bundle-analyzer with Webpack 4:

DepreciationWarning: Tappable.plugin is deprecated. Use new API on `.hooks` instead

Technical info

  • Webpack Bundle Analyzer version: 2.10.0
  • Webpack version: Webpack 4.0.0-beta.2
  • Node.js version: 9
  • npm/yarn version: 1.3.2
  • OS: Linux

Debug info

How do you use this module? As CLI utility or as plugin?

Plugin inside Size Limit

If plugin, what options were provided? (e.g. new BundleAnalyzerPlugin({ analyzerMode: 'disabled', generateStatsFile: true }))

      openAnalyzer: true,
      analyzerMode: 'server',
      defaultSizes: 'gzip'

What other Webpack plugins were used?

compression-webpack-plugin and uglifyjs-webpack-plugin

Related issue: ai/size-limit#42

@valscion
Copy link
Member

Hi, and thanks for raising an issue! So to clarify, webpack-bundle-analyzer works but it outputs a deprecation warning with webpack 4?

The deprecation warning is a result of this line:

compiler.plugin('done', stats => {

Do you have an idea of how a plugin can support both webpack 3 and 4 at the same time without outputting deprecation warnings?

@ai
Copy link
Contributor Author

ai commented Feb 21, 2018

@valscion

So to clarify, webpack-bundle-analyzer works but it outputs a deprecation warning with webpack 4?

Yeap :)

Do you have an idea of how a plugin can support both webpack 3 and 4 at the same time

In the same cases, I used this method:

if (compiler.hooks) {
  // Webpack >= 4
} else {
  // Webpack < 4
}

But I am not 100% sure about this case.

@valscion
Copy link
Member

Should be pretty easy to do that :). Would you be open to trying this approach out with webpack 4? https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/master/CONTRIBUTING.md has intructions on how to setup the build pipeline for this project and link to your own project for local testing. Or maybe @jaydenseric would like to give this a try if you've got time?

@ai
Copy link
Contributor Author

ai commented Feb 21, 2018

@valscion sure, if nobody closes it until Friday, I will try to fix (Friday is my open source day =^_^=).

@valscion
Copy link
Member

👍 thanks!

I noticed that CONTRIBUTING.md still has a mention of dev branch, which to my recollection has been deleted from this repository quite some time ago already. #155 hopefully clarifies the situation a bit ☺️

@alexander-akait
Copy link
Member

@valscion better do major release than use if (compiler.hooks) {} else {}, we will do this in contrib after webpack 4 was release, right now is it just warning and it is not critical

@ai
Copy link
Contributor Author

ai commented Feb 21, 2018

@evilebottnawi if you will do major release all next Bundle Analyzer releases will be unavailable for Webpack 3 users

@valscion
Copy link
Member

@valscion better do major release than use if (compiler.hooks) {} else {}, we will do this in contrib after webpack 4 was release, right now is it just warning and it is not critical

If possible @evilebottnawi, I'd rather support both webpack 3 and 4. We only use the done hook in this plugin so compared to other plugins and loaders, supporting both versions should be trivial. Does this sound like a good approach to you?

@th0r
Copy link
Collaborator

th0r commented Feb 21, 2018

@evilebottnawi is there a recommended way to support both Webpack 4 and 3 APIs? @sokra?

@michael-ciniawsky
Copy link
Member

webpack >= 4 supports the 'old' Plugin API, so I recommend the compat is handled in/by webpack itself. There should simply be a flag or the like to suppress the warnings instead of working around that by plugin/loader authors :). It's still just a warning and the code is functional

@sokra
Copy link
Member

sokra commented Feb 21, 2018

you can do the following:

if(compiler.hooks) {
  compiler.hooks.done.tap(...);
} else {
  compiler.plugin(...);
}

@valscion
Copy link
Member

There should simply be a flag or the like to suppress the warnings instead of working around that by plugin/loader authors :). It's still just a warning and the code is functional

Ah, but if we'd rather have the code to be optimal for webpack 4 and if it is simple and straightforward to do so, it might make more sense than adding special flags.

The piece of code @sokra posted above is what I'd accept as a PR.

@ai
Copy link
Contributor Author

ai commented Feb 23, 2018

@valscion I made a PR #156

@valscion
Copy link
Member

Fixed in v2.10.1 🎉, thanks @ai for the pull request!

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

No branches or pull requests

6 participants