`webpack –profile –json` “RangeError: Invalid string length” when outputting _huge_ JSON file

Do you want to request a feature or report a bug?


What is the current behavior?

When running webpack with --profile --json flags, and the JSON data to be output is rather big, it fails with this error:

			process.stdout.write(JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n");

RangeError: Invalid string length
    at join (native)
    at Object.stringify (native)
    at compilerCallback (/home/simon/dev/otrl/booking-engine/node_modules/webpack/bin/webpack.js:337:30)

If the current behavior is a bug, please provide the steps to reproduce.

Well, I guess you need a project with enough entry points, and a complicated enough module graph that the size of the profile is quite large. I will try to create a reproducible repo, but actually this is demonstrable with node & no dependencies:


What is the expected behavior?

The JSON should be output to stdout

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

  • node v6.10.0
  • webpack 2.3.3
  • Ubuntu 16.04.1 LTS

Author: Fantashit

2 thoughts on “`webpack –profile –json` “RangeError: Invalid string length” when outputting _huge_ JSON file

  1. I have a large project with many entry points and I also get this error after upgrading to NodeJS 10.15.3.

    I was able to modify webpack-cli so that it streams out the JSON representation of the Webpack stats object here: cjlarose/webpack-cli@0169c33.

    In my case, that fork successfully generated a JSON file containing 1447518306 bytes. This is larger than the maximum string size supported by NodeJS 10 on a 64-bit platform (1073741799 bytes)

    In short, I don’t think that relying on larger string sizes in NodeJS 10 is an appropriate way to dismiss this issue. There are real projects that have stats objects that are really large, and many of those projects are exactly the kinds of projects that have a strong need to gather statistics from webpack in order to analyze and optimize bundles.

    Would a change to write the stats object as JSON using a stream be a welcome change?

Comments are closed.