shellscape / webpack-manifest-plugin

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

[Bug] assets.chunks is undefined webpack@5.0.0 #219

Closed kyoncy closed 3 years ago

kyoncy commented 3 years ago

Environment

webpack: v5.0.0

Error Log

✖ 「wdm」: TypeError: Cannot read property 'length' of undefined
    at /Users/xxx/project/node_modules/webpack-manifest-plugin/lib/plugin.js:129:39
    at Array.reduce (<anonymous>)
    at ManifestPlugin.<anonymous> (/Users/xxx/project/node_modules/webpack-manifest-plugin/lib/plugin.js:116:26)
    at Hook.eval [as callAsync] (eval at create (/Users/xxx/project/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:7:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/xxx/project/node_modules/webpack/node_modules/tapable/lib/Hook.js:18:14)
    at Compiler.emitAssets (/Users/xxx/project/node_modules/webpack/lib/Compiler.js:736:19)
    at /Users/xxx/project/node_modules/webpack/lib/Watching.js:80:21
    at processTicksAndRejections (internal/process/task_queues.js:79:11)

add to https://github.com/shellscape/webpack-manifest-plugin/blob/master/lib/plugin.js#L127 the code below

console.log(assets.chunks)     // undefined
console.log(assets.chunkNames) // [ 'bundle' ]

Because of webpack changes, chunk is undefined.

Suggestion

https://github.com/shellscape/webpack-manifest-plugin/blob/49f34a5c56db85c5076d1fae7f7be980022f932c/lib/plugin.js#L128

I suggest chunks to chunkNames.

Passed when using webpack@4.44.2. But, I haven't tried webpack@2.x.x, webpack@3.x.x.

shellscape commented 3 years ago

Thanks for opening an issue. We've just undeprecated the package and are working on getting everything setup to continue development.

shellscape commented 3 years ago

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

0x78f1935 commented 3 years ago

I've read the updates and I'm happy talented people are keeping this package alive. I do however would like to suggest to re-open this issue. It seems to be still relevant for webpack V5.

[webpack-cli] TypeError: Cannot read property 'length' of undefined
    at D:\Work\portal\node_modules\webpack-manifest-plugin\lib\plugin.js:129:39
    at Array.reduce (<anonymous>)
    at ManifestPlugin.<anonymous> (D:\Work\portal\node_modules\webpack-manifest-plugin\lib\plugin.js:116:26)
    at _next0 (eval at create (D:\Work\portal\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:15:1)
    at eval (eval at create (D:\Work\portal\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:35:1)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

This only happens when adding this code to webpack.config.js

plugins: [
        new Manifest({
            // fileName: './manifest.json',
            // publicPath: '/static/react/',
        }),
]

The suggestion by OP works but I don't see a PR which relates to this issue and one which is still open.


Issue seems to be webpack5. Universal chunks are not implemented yet. https://github.com/webpack/webpack/issues/11660

https://github.com/shellscape/webpack-manifest-plugin/pull/224

mixa9269 commented 3 years ago

Any updates?

lornally commented 3 years ago

i meet this too. only with this:

new Manifest(),
0x78f1935 commented 3 years ago

Boys! It seems to be fixed https://github.com/shellscape/webpack-manifest-plugin/commit/100cbe272278fea532089393dc3445c811816005

I can confirm it works again on webpack5!

Thanks @shellscape !