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

TypeError: Cannot read property 'map' of undefined

ChrisCinelli opened this issue · comments

Error:

  /usr/local/lib/node_modules/webpack-bundle-size-analyzer/build/size_tree.js:51
    var modules = stats.modules.map(function (mod) {
                               ^
TypeError: Cannot read property 'map' of undefined
    at Object.dependencySizeTree (/usr/local/lib/node_modules/webpack-bundle-size-analyzer/build/size_tree.js:51:32)
    at printStats (/usr/local/lib/node_modules/webpack-bundle-size-analyzer/build/cli.js:7:29)
    at Socket.<anonymous> (/usr/local/lib/node_modules/webpack-bundle-size-analyzer/build/cli.js:20:50)
    at Socket.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickCallback (node.js:355:11)

Can you provide the webpack --json output that you were trying to analyze with the tool?

I'm getting this same error, using both node 0.12 and 5.0. The error only occurs when Webpack is building multiple bundles (one for JS and one for CSS in my current project); if I build just one, it works.

Gist with webpack config and resulting JSON for a test build: https://gist.github.com/paulrayes/25012db728fc0ae946f8

I got same errors when building multiple bundles.

Minimal webpack.config.js that reproduces the problem:

module.exports = [{
    entry: './lib/browser',
    output: {
        filename: '[name].js',
    },
}];

I found a workaround. You can use a plugin to save a json file for a single bundle, then this tool work work with it:

    plugins: [function() {
        this.plugin('done', function(stats) {
            require('fs').writeFileSync(
                path.join(__dirname, 'stats.json'),
                JSON.stringify(stats.toJson())
            );
        });
    }]

Webpack's normal analyzer (http://webpack.github.io/analyse/) seems to have a similar bug so I am using this for now instead of the CLI switch.