You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeError: Cannot read property 'forEach' of undefined #490
Are you able to post a stats file that causes this issue?
It's possible that some presence checks are needed where we use .forEach. It's possible that when usage of lodash was made smaller, there now is less protection against some data missing and .forEach still being called on them:
I completely understand, but I think that more explicit errors can be very helpful, for example check if bundleStats.assets is defined, and if it isn't print a more helpful error message, maybe with a possible reason as to why it's undefined.
TypeError: Cannot read property 'forEach' of undefined
Is very cryptic, and doesn't even help me understand if there's an issue with this package, my config, or something else.
That is an error that merely comes because something is undefined and then .forEach is getting called on it. We need to know what is undefined to fix it, or to even add a better error message if we can't fix it.
Without a stats JSON file, we don't know what is undefined and we can't write tests that would ensure we don't regress any error message feature or a test fix in the future.
Probably the problem is with the stats.json file and what is declared on webpack file that will generate json file. here you can find the possible configurations for stats conf. Maybe with a 'normal' config the problem should be gone...
"The stats option lets you precisely control what bundle information gets displayed."
Yes, I asked about a reproduction as a test case and creating a pull request that aims to fix this bug.
I don't have time right now to tackle this and it seems that this isn't affecting too many people right now. The quickest way to get this fixed is to help in fixing it as part of open source ☺️
Reacted by Sebastian Nowak, manzonif, amr-m-awad, Roman Martynov, Sahar Beker, Eric Augusto, Rahmat Ali and dbPietah
I added the null coalescing operator and then it failed again. Upon inspection it looks like bundleStats.assets was empty, so I figured it was missing a property in the stats when running webpack --profile --json, so I changed the profiling command to webpack --profile --json --stats verbose, and it started working 🚀
Thanks for the insight @hecerinc! I wonder if there's some place in the README.md here where this --stats verbose would be useful to highlight? If so, feel free to send a PR for said update ☺️
Activity
valscion commentedon Jan 24, 2022
Are you able to post a stats file that causes this issue?
It's possible that some presence checks are needed where we use
.forEach. It's possible that when usage of lodash was made smaller, there now is less protection against some data missing and.forEachstill being called on them:sahariko commentedon Jan 24, 2022
I don't think it would be possible, since it's a proprietary codebase 😕
sahariko commentedon Jan 24, 2022
But if it helps in any way we're exporting an array.
When returning an array we're getting
.filtererrors, when returning an object (Webpack config), we're getting the.forEacherror.If I had to take a shot I would assume these lines are problematic:
https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/395/files#diff-cc250993338f2c875d952782d3e6e5465c510ee355a68adb9f8f1ccd5d446823L51
https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/395/files#diff-cc250993338f2c875d952782d3e6e5465c510ee355a68adb9f8f1ccd5d446823L210
valscion commentedon Jan 24, 2022
We can't fix it unless we can make a test case. Otherwise we're likely to break the fix in a future release if we don't have test coverage.
sahariko commentedon Jan 24, 2022
I completely understand, but I think that more explicit errors can be very helpful, for example check if
bundleStats.assetsis defined, and if it isn't print a more helpful error message, maybe with a possible reason as to why it's undefined.Is very cryptic, and doesn't even help me understand if there's an issue with this package, my config, or something else.
valscion commentedon Jan 24, 2022
That is an error that merely comes because something is
undefinedand then.forEachis getting called on it. We need to know what is undefined to fix it, or to even add a better error message if we can't fix it.Without a stats JSON file, we don't know what is undefined and we can't write tests that would ensure we don't regress any error message feature or a test fix in the future.
ilias-t commentedon Jan 31, 2022
Here's a
compilation-stats.jsonfile that repros the issue (apologies for it being rather large)compilation-stats.json.zip
thecristen commentedon Apr 14, 2022
hi. here's a stats.json file that produces this error, using latest webpack, webpack-cli, webpack-bundle-analyzer:
stats.json.zip
tiagoevanp commentedon May 31, 2022
Probably the problem is with the stats.json file and what is declared on webpack file that will generate json file. here you can find the possible configurations for stats conf. Maybe with a 'normal' config the problem should be gone...
sebastian-nowak commentedon Mar 1, 2023
Any updates on this? This is still an issue in the latest lib version, and it makes it unusable.
valscion commentedon Mar 1, 2023
If someone is able to create a pull request that reproduces this case with a test case and also fixes it then I'll consider accepting it☺️
sahariko commentedon Mar 1, 2023
@valscion Don't know about a fix, but both @ilias-t and @thecristen provided Zip files with a reproducible error.
valscion commentedon Mar 2, 2023
Yes, I asked about a reproduction as a test case and creating a pull request that aims to fix this bug.
I don't have time right now to tackle this and it seems that this isn't affecting too many people right now. The quickest way to get this fixed is to help in fixing it as part of open source☺️
Ismaestro commentedon Sep 26, 2024
Ok, so as an alternative, use source-map-explorer...
hecerinc commentedon Jan 6, 2025
FYI, I dug into the code a little bit, and it was analyzer.js:getViewerData() function returning the undefined in this chunk:
I added the null coalescing operator and then it failed again. Upon inspection it looks like
bundleStats.assetswas empty, so I figured it was missing a property in the stats when runningwebpack --profile --json, so I changed the profiling command towebpack --profile --json --stats verbose, and it started working 🚀valscion commentedon Jan 8, 2025
Thanks for the insight @hecerinc! I wonder if there's some place in the README.md here where this☺️
--stats verbosewould be useful to highlight? If so, feel free to send a PR for said updateronakmaheshwari commentedon Oct 16, 2026
@valscion can you close it as its merged