robertknight / webpack-bundle-size-analyzer

A tool for finding out what contributes to the size of Webpack bundles

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Confusing error message if `stats.children` is disabled in webpack config

gustavohenke opened this issue · comments

Hi!
I tried running webpack-bundle-size-analyzer against the output generated by my app for the first after some iterations, and was surprised by the following error:

λ webpack --json --verbose | webpack-bundle-size-analyzer
C:\Users\gustavo\AppData\Roaming\npm\node_modules\webpack-bundle-size-analyzer\build\src\size_tree.js:136
        return stats.children.map(bundleSizeTree);
                             ^

TypeError: Cannot read property 'map' of undefined
    at Object.dependencySizeTree (C:\Users\gustavo\AppData\Roaming\npm\node_modules\webpack-bundle-size-analyzer\build\src\size_tree.js:136:30)
    at printStats (C:\Users\gustavo\AppData\Roaming\npm\node_modules\webpack-bundle-size-analyzer\build\src\cli.js:14:30)
    at Socket.<anonymous> (C:\Users\gustavo\AppData\Roaming\npm\node_modules\webpack-bundle-size-analyzer\build\src\cli.js:43:50)
    ...

One change I made was to hide most stats from the webpack logs with the stats key my webpack.config.js:

stats: {
    assets: true,
    children: false,
    chunks: false,
    errors: true,
    errorDetails: true,
    modules: false,
    timings: true,
    colors: true
}

Obviously this was the cause of the error above.
The only thing I found to work is to remove these. I haven't tried any combination of webpack CLI flags apart from --verbose --json (which didn't work).

It would be nice to document this problem and how to solve it, so others don't get into this trap as well.
And if you know about a more elegant way around this, let me know!

Thanks for the report. I didn't know that it was possible to configure webpack in such a way that this information would be missing from the JSON output. It shouldn't be too difficult to to spit out a more helpful error message.

And thank you for making the title of this issue clearer as well 😊