codepunkt/webpack-license-plugin

Webpack Deprecation Warning during build proccess

ddelkhosh opened this issue ยท 8 comments

After using this plugin in build process this warning will be appeared on output:

(node:21144) [DEP_WEBPACK_COMPILATION_OPTIMIZE_CHUNK_ASSETS] DeprecationWarning: optimizeChunkAssets is deprecated (use Compilation.hooks.processAssets instead and use one of Compilation.PROCESS_ASSETS_STAGE_* as stage option)
(Use node --trace-deprecation ... to show where the warning was created)

node v14.16.1
npm 6.14.13
webpack 5.44.0
angular/cli 12.1.4

tdev9 commented

Same issue

Same issue in Version 4.2.1

โ ™ Generating browser application bundles (phase: setup)...(node:11500) [DEP_WEBPACK_COMPILATION_OPTIMIZE_CHUNK_ASSETS] DeprecationWarning: optimizeChunkAssets is deprecated (use Compilation.hooks.processAssets instead and use one of Compilation.PROCESS_ASSETS_STAGE_* as stage option)
(Use node --trace-deprecation ... to show where the warning was created)

angular/cli@13.0.4
webpack@5.64.1
node v14.17.5
npm v6.14.14

Please do something

@danieldaeschle Feel free to open a Pull Request ๐Ÿ‘๐Ÿป

Took a look at the documentation for the deprecation upgrade path. I determined replacing the handleCompilation method with the following solves it (Notably the processAssets portion):

  public handleCompilation(
    compiler: webpack.Compiler,
    compilation: webpack.compilation.Compilation
  ) {
    if (typeof compilation.hooks !== 'undefined') {
      if (typeof compilation.hooks.processAssets !== 'undefined') {
        compilation.hooks.processAssets.tapAsync({
          name: 'webpack-license-plugin',
          stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
        },
          (assets, callback) => {
            this.handleChunkAssetOptimization(compiler, compilation, compilation.chunks, callback);
          }
        );
      } else {
        compilation.hooks.optimizeChunkAssets.tapAsync('webpack-license-plugin', this.handleChunkAssetOptimization.bind(this, compiler, compilation));
        // @ts-ignore
      }
      // @ts-ignore
    } else if (typeof compilation.plugin !== 'undefined') {
      // @ts-ignore
      compilation.plugin(
        'optimize-chunk-assets',
        this.handleChunkAssetOptimization.bind(this, compiler, compilation)
      )
    }
  }

I could not find a way to both upgrade TS types to support processAssets without having to retype everything to Webpack 5. If anyone has experience in that, would be happy to collaborate for a PR.

Sorry, Is this fixed yet? I am having the same issue

Any update when a new release with the fix will be available?

Would be great to get this one published to npm.