Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nyc merge for large number of files throws "Invalid string length" error #1451

Closed
parvez opened this issue Mar 14, 2022 · 2 comments · Fixed by #1570
Closed

nyc merge for large number of files throws "Invalid string length" error #1451

parvez opened this issue Mar 14, 2022 · 2 comments · Fixed by #1570

Comments

@parvez
Copy link

parvez commented Mar 14, 2022

We run 20+ parallel runs of cypress that generate 20 different coverage${ID}-final.json stored in cypress/coverage

Expected Behavior

$(npm bin)/nyc merge cypress/coverage cypress/coverage/coverage-final.json should merge them into a single coverage file without issue.

Observed Behavior

$(npm bin)/nyc merge cypress/coverage cypress/coverage/coverage-final.json throws this error:

RangeError: Invalid string length

Likely issue

Might be happening due to nodejs/node#35973 and thus lowering the number of runs to 14 works as the size of the json is lower than 500MB

Screen Shot 2022-03-14 at 2 21 23 PM

@kunaljaydesai
Copy link

I ran into the same issue. I fixed it by reducing the size of the JSON files. For example, for my use case, we didn't need code coverage for files in node_modules directory. Perhaps the same or something similar can apply to your case.

@skimi
Copy link
Contributor

skimi commented Jun 26, 2024

A big reason merge can hit this error quickly is that it stringifies pretty json with a lot of white space meaning huge json
https://github.com/istanbuljs/nyc/blob/main/lib/commands/merge.js#L44

Going from JSON.stringify(map, null, 2) to simple JSON.stringify(map) adds a lot of leeway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants