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 5 support #435

Closed
marcneander opened this issue Oct 27, 2020 · 13 comments
Closed

webpack 5 support #435

marcneander opened this issue Oct 27, 2020 · 13 comments
Labels
bug Something isn't working deprecation

Comments

@marcneander
Copy link

Hello! Thanks for a great plugin!

We're getting errors using webpack 5.

Conflict: Multiple assets emit different content to the same filename oss-licenses.json.

I can create a repro repo but don't have time for that right now.

@codepunkt
Copy link
Owner

@marcneander Thanks for reporting this!

It probably depends on the exact version of webpack 5 that you're using and might be related to a few other factors. A reproduction repository would be very nice - you could possibly also do this on codesandbox.com

@pathmapper
Copy link

fwiw: I had no issues using the plugin with webpack 5.

@archfz
Copy link

archfz commented Dec 15, 2020

Same issue here.

@silverwind
Copy link

silverwind commented Dec 23, 2020

I see two distinct deprecation warnings and one error on a project that has child compilers and other advanced stuff. Making a repro would be hard but I guess you can work off these messages. Most are related to deprecated APIs.

DeprecationWarning: optimizeChunkAssets is deprecated (use Compilation.hook.processAssets instead and use one of Compilation.PROCESS_ASSETS_STAGE_* as stage option)
    at WebpackLicensePlugin.handleCompilation (node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:73:51)
    at Hook.eval [as call] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:206:1)
    at Hook.CALL_DELEGATE [as _call] (node_modules/tapable/lib/Hook.js:14:14)
    at Compiler.newCompilation (node_modules/webpack/lib/Compiler.js:988:26)
    at node_modules/webpack/lib/Compiler.js:1029:29
    at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:22:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)
    at Compiler.compile (node_modules/webpack/lib/Compiler.js:1024:28)
    at node_modules/webpack/lib/Watching.js:112:19
    at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:22:1)
DeprecationWarning: Chunk.modulesIterable: Use new ChunkGraph API
    at Function.getChunkGraphForChunk (node_modules/webpack/lib/ChunkGraph.js:1402:10)
    at Chunk.get modulesIterable [as modulesIterable] (node_modules/webpack/lib/Chunk.js:177:33)
    at WebpackChunkModuleIterator.iterateModules (node_modules/webpack-license-plugin/dist/WebpackChunkModuleIterator.js:19:26)
    at WebpackChunkIterator.iterateChunks (node_modules/webpack-license-plugin/dist/WebpackChunkIterator.js:30:37)
    at WebpackLicensePlugin.<anonymous> (node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:90:51)
    at step (node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:33:23)
    at Object.next (node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:14:53)
    at node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:4:12)
Error: Module.entryModule: Multiple entry modules are not supported by the deprecated API (Use the new ChunkGroup API)
    at Chunk.get entryModule [as entryModule] (node_modules/webpack/lib/Chunk.js:119:10)
    at WebpackChunkModuleIterator.iterateModules (node_modules/webpack-license-plugin/dist/WebpackChunkModuleIterator.js:42:19)
    at WebpackChunkIterator.iterateChunks (node_modules/webpack-license-plugin/dist/WebpackChunkIterator.js:30:37)
    at WebpackLicensePlugin.<anonymous> (node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:90:51)
    at step (node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:33:23)
    at Object.next (node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:14:53)
    at node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:4:12)
    at WebpackLicensePlugin.handleChunkAssetOptimization (node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:80:16)
    at node_modules/webpack/lib/Compilation.js:426:47
    at fn (node_modules/webpack/lib/Compilation.js:346:9)
    at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)
    at cont (node_modules/webpack/lib/Compilation.js:2088:33)
    at node_modules/webpack/lib/Compilation.js:2134:9

@dlech
Copy link

dlech commented Jan 16, 2021

Conflict: Multiple assets emit different content to the same filename oss-licenses.json.

I ran into the same error message with webpack 4. I think this is happening because handleChunkAssetOptimization is called for each chunk which means this runs multiple times:

await licenseFileWriter.writeLicenseFiles(filenames, options)

So we are ending up with a license file for only the modules referenced by the last chunk.

@hdmr14
Copy link

hdmr14 commented Feb 26, 2021

same issue here.

@codepunkt
Copy link
Owner

Conflict: Multiple assets emit different content to the same filename oss-licenses.json.

I ran into the same error message with webpack 4. I think this is happening because handleChunkAssetOptimization is called for each chunk which means this runs multiple times:

await licenseFileWriter.writeLicenseFiles(filenames, options)

So we are ending up with a license file for only the modules referenced by the last chunk.

This plugin hooks into the compilers compile hook. Afaik, this is only called once for each compilation - which might be why we're seeing problems on projects with child compilers.

Webpack's documentation for plugin developers is severely lacking. I tried getting rid of the deprecation warnings, but could not do it without impacting this plugins functionality. If any of you can help here, it would be very appreciated.

Speaking of errors like the Multiple assets emit different content to the same filename, I'm still looking for a reproducible example so I can dig into this.

@hdmr14
Copy link

hdmr14 commented Mar 3, 2021

I have no times for fixing this full-featured plugin for now, but I made tiny license plugin for my project, It exports single licenses.txt which contains license info of all chunks.

It looks like below.

class ExampleWebpackPlugin {
  apply(compiler) {
    // use emit hook not compilation
    compiler.hooks.emit.tapAsync(
      "ExampleWebpackPlugin",
      (compilation, callback) => {
        // run at once
        // initializing something here
        compilation.chunks.forEach(
          (chunk) => {
            // run for each chunks
            // some license fetch code here
          }
        );
        // run at once here
        // set license output to compilation.assets here

        callback();
      }
    );
  }
}

bit differences from webpack-license-plugin

  • using emit hook, not compilation
  • gets chunks data via compilation.chunks api

I hope this helps something.

@slawo-ch
Copy link

Attaching repro:
repro.zip

λ: $ cd repro

λ:repro $ npm install
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.

added 569 packages, and audited 570 packages in 11s

32 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
λ:repro $ npm run build

> [email protected] build
> webpack --mode production

(node:12280) [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:12280) [DEP_WEBPACK_CHUNK_MODULES_ITERABLE] DeprecationWarning: Chunk.modulesIterable: Use new ChunkGraph API
(node:12280) [DEP_WEBPACK_CHUNK_ENTRY_MODULE] DeprecationWarning: Chunk.entryModule: Use new ChunkGraph API
(node:12280) UnhandledPromiseRejectionWarning: Error: Module.entryModule: Multiple entry modules are not supported by the deprecated API (Use the new ChunkGroup API)
    at Chunk.get entryModule [as entryModule] (/Users/slawo/Desktop/repro/node_modules/webpack/lib/Chunk.js:119:10)
    at WebpackChunkModuleIterator.iterateModules (/Users/slawo/Desktop/repro/node_modules/webpack-license-plugin/dist/WebpackChunkModuleIterator.js:42:19)
    at WebpackChunkIterator.iterateChunks (/Users/slawo/Desktop/repro/node_modules/webpack-license-plugin/dist/WebpackChunkIterator.js:30:37)
    at WebpackLicensePlugin.<anonymous> (/Users/slawo/Desktop/repro/node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:90:51)
    at step (/Users/slawo/Desktop/repro/node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:33:23)
    at Object.next (/Users/slawo/Desktop/repro/node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:14:53)
    at /Users/slawo/Desktop/repro/node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/slawo/Desktop/repro/node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:4:12)
    at WebpackLicensePlugin.handleChunkAssetOptimization (/Users/slawo/Desktop/repro/node_modules/webpack-license-plugin/dist/WebpackLicensePlugin.js:80:16)
(node:12280) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:12280) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
λ:repro $

@JonasGilg
Copy link

Hi, I have the same problem. The output from @slawo-ch matches mine exactly. Is there ongoing development towards a fix?

Or is there a workaround that I can use in the meantime? This is the only project I found doing what I wanted.

@codepunkt
Copy link
Owner

Fixed by #510, released as 4.1.3

@flyon
Copy link

flyon commented May 12, 2022

I still have errors with webpack 5 with version 4.2.2 installed

(node:16788) [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)

From WebpackLicencePlugin.ts line 70

    ...
    if (typeof compilation.hooks !== 'undefined') {
      compilation.hooks.optimizeChunkAssets.tapAsync(
        'webpack-license-plugin',
        this.handleChunkAssetOptimization.bind(this, compiler, compilation)
      )

@mbaklor
Copy link

mbaklor commented Feb 20, 2023

I too still get it, with webpack 5 and version 4.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working deprecation
Projects
None yet
Development

No branches or pull requests