trivago/parallel-webpack

JSON.stringify, RangeError: Invalid String Length

josephliccini opened this issue · 3 comments

Hi!

Thanks for this tool!! It has sped up our compilations for webpack immensely.

We are using Angular, and the amount of webpack work Angular does is huge. We do inmemory compilation of TypeScript and NGC, and other optimizations, and it gets up past 4GB of compilation.

We specify --max-old-space-size to node to complete the compilation. I assume this is passed along in the Node workers, correct?

Also, we are hitting this error on JSON.stringify, when stats: true is set on the run() method.

internal/child_process.js:626
    var string = JSON.stringify(message) + '\n';
                      ^

RangeError: Invalid string length
    at Object.stringify (native)
    at process.target._send (internal/child_process.js:626:23)
    at process.target.send (internal/child_process.js:538:19)

I am pretty sure this is due to a huge stats object being passed in. Thoughts on how to get this to not crash?

Thanks!
Joe

pago commented

We should probably wrap the stringify call with a try-catch to avoid this error from stopping an otherwise successful run. Would you like to submit a PR for that?

yeah I can do that sometime this week probably. I thought maybe passing in something like stats: 'errors-only' detailed here: https://webpack.js.org/configuration/stats/#components/sidebar/sidebar.jsx

I am thinking:

  • wrap in try-catch as you say
  • in error message, suggest subsetting the stats object.
    -- We are only interested in webpack build errors, and size of bundles, so I can probably subset it as explained in the above link, then it shouldn't fail with this error

I suppose I have to see if subsetting the stats object with webpack's API will properly provide a smaller object with only the specified fields to webpack-parallel. I will report back my findings.

Thanks!

I have the same problem ,how can i resolve it?
Cause our angular project is too large,we can't package it success with webpack. Help me please!