Skip to content

getViewerData throws "Maximum call stack size exceeded" when a chunk has about 130,000 modules #752

Closed

Description

@G26karthik

Have you used AI?

Yes. AI tools accelerated this work: finding the bug and writing the reproduction. I reviewed it and ran the reproduction.

Bug Description

When one chunk in the stats lists about 130,000 modules or more, getViewerData throws RangeError: Maximum call stack size exceeded, so the plugin and the CLI log "Couldn't analyze webpack bundle" and produce no report. I found this while reading src/analyzer.js: flatten() copies each chunk's module list with res.push(...cur), which passes every module as a separate call argument.

Link to Minimal Reproduction and step to reproduce

// repro.js, after `npm i [email protected]`
const { getViewerData } = require("webpack-bundle-analyzer/lib/analyzer");

const modules = Array.from({ length: 130_000 }, (_, id) => ({
  id,
  name: `./src/m${id}.js`,
  size: 10,
  chunks: [0],
}));

getViewerData({
  assets: [{ name: "bundle.js", chunks: [0], size: 10 }],
  chunks: [{ id: 0, modules }],
});

Run node repro.js. With 100,000 modules it works.

Expected Behavior

The chart data is returned, as it is for smaller chunks.

Actual Behavior

RangeError: Maximum call stack size exceeded
    at flatten (node_modules/webpack-bundle-analyzer/lib/analyzer.js:75:11)

Environment

webpack-bundle-analyzer 5.4.2 (same on main at cec6ac6)
Node.js 22.23.2, Windows 11

Is this a regression?

Yes (please specify version below)

Last Working Version

4.9.1

Additional Context

4.9.1 handles 500,000 modules in one chunk and 4.10.0 fails at 130,000. #612 replaced lodash.flatten, which copies in a loop, with the local flatten. Copying the elements in a loop fixes it. I have a fix and a test ready if that is fine with you.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions