Skip to content

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

Description

@gustavohenke

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions