shellscape / webpack-manifest-plugin

webpack plugin for generating asset manifests
MIT License
1.43k stars 186 forks source link

Support webpack@5 #186

Closed irudoy closed 3 years ago

irudoy commented 5 years ago
TypeError: Cannot read property 'call' of undefined
    at ManifestPlugin.<anonymous> (/.../node_modules/webpack-manifest-plugin/lib/plugin.js:191:53)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/.../node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:9:1)
    at AsyncSeriesHook.lazyCompileHook (/.../node_modules/tapable/lib/Hook.js:154:20)
    at Compiler.emitAssets (/.../node_modules/webpack/lib/Compiler.js:448:19)
    at process.nextTick (/.../node_modules/webpack/lib/Compiler.js:249:10)
    at processTicksAndRejections (internal/process/next_tick.js:74:9)
(node:28406) DeprecationWarning: Compilation.chunks was changed from Array to Set (using Array method 'reduce' is deprecated)
mAAdhaTTah commented 5 years ago

I'm getting this error on webpack@4 w/ multiple compilers (e.g. module.exports = [... multiple configs ...]).

xeonicca commented 5 years ago

I had the same problem and mine was caused by smart measure webpack plugin which may fail during incremental build.

ycjcl868 commented 5 years ago

same problems. How to solve the problem? @mastilver

VictorQueiroz commented 4 years ago

I also have the same problem using the multi-compiler feature. How can we fix this? webpack@4.35.3

mastilver commented 4 years ago

Can you all confirm it's been fixed on 2.2.0? (thank you @ian-craig )

ian-craig commented 4 years ago

Thanks @mastilver

2.2.0 with Webpack 5.0.0-alpha.26 seems to be working correctly in my project. I just have a simple setup though, so no other plugins depending on the manifest or anything.

kirill-konshin commented 4 years ago

There are other problems too:

✖ 「wdm」: TypeError: Cannot read property 'length' of undefined
    at /Users/dis/Sites/web-modules-core/build/node_modules/webpack-manifest-plugin/lib/plugin.js:129:39
    at Array.reduce (<anonymous>)
    at ManifestPlugin.<anonymous> (/xxx/node_modules/webpack-manifest-plugin/lib/plugin.js:116:26)
    at _next0 (eval at create (/xxx/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:19:1)
    at eval (eval at create (/xxx/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:34:1)
    at /xxx/node_modules/html-webpack-plugin/index.js:317:11
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
ceesvanegmond commented 4 years ago

Got same problem as @kirill-konshin .

kirill-konshin commented 4 years ago

Seems to be working now, noticed one issue though: webpack-manifest-plugin@3.0.0-rc.0" has unmet peer dependency "webpack@4".

keeganstreet commented 3 years ago

Hi, this error is still occurring with webpack-manifest-plugin@2.2.0 and webpack@5.0.0-beta.22. Here is the error message:

[DEP_WEBPACK_DEPRECATION_ARRAY_TO_SET] DeprecationWarning: Compilation.chunks was changed from Array to Set (using Array method 'reduce' is deprecated)
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
at node_modules/webpack-manifest-plugin/lib/plugin.js:129:39
at Array.reduce (<anonymous>)
at ManifestPlugin.<anonymous> (node_modules/webpack-manifest-plugin/lib/plugin.js:116:26)

Here's the line that is treating compilation.chunks as an Array, when it is now a Set: https://github.com/danethurber/webpack-manifest-plugin/blob/master/lib/plugin.js#L87

keeganstreet commented 3 years ago

I wrapped compilation.chunks, chunk.files, and stats.assets in Array.from just to get a build working. Webpack is giving another warning about this module:

[DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future, all modifications are deprecated.
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.
arxeiss commented 3 years ago

@keeganstreet Is somewhere possible to download a functional version of this plugin? No matter the Deprecation warning. I want to use some features of Webpack 5 but I want to have manifest as well.

Thanks

arxeiss commented 3 years ago

So I tried to make it work as @keeganstreet suggested with Array.from wraps. And this is what I did to work with Webpack 5. It is not ideal, but acceptable for me for now.

webpack.config.js

- const ManifestPlugin = require('webpack-manifest-plugin');
+ const ManifestPlugin = require('./webpack-manifest-plugin'); // local file

Then I downloaded the current JS file from the master branch. lib/plugin.js and saved it next to webpack.config.js with name webpack-manifest-plugin.js. And updated those lines:

webpack-manifest-plugin.js

// This changes is on line 87
- var files = compilation.chunks.reduce(function(files, chunk) {
+ var files = Array.from(compilation.chunks).reduce(function(files, chunk) {

// This changes is on line 128
// From Webpack 5, I think "the hack" where this code lives is not needed.
// So I'm returning files directly. Otherwise ignore the return and use the rest
- var isEntryAsset = asset.chunks.length > 0;
+ return files;
+ var isEntryAsset = Array.from(asset.chunks || []).length > 0;

Hope this helps someone to use this plugin with Webpack 5 until the proper fix will be released. There are some pitfalls with this approach still.

kirill-konshin commented 3 years ago

FYI, I've successfully used "webpack-manifest-plugin": "3.0.0-rc.0".

shellscape commented 3 years ago

Hey folks, please see #222 for updates on v5 support.