Open Nicolas-Menettrier opened 10 months ago
A repro would help a lot in our investigation. The error could be due to JSON.stringify
not being able to handle a large payload, but I need to confirm that is indeed the case since I haven't run into this limit yet on some pretty large monorepos.
I also notice old @nrwl/
scoped packages, you can safely remove them.
Sadly I can't share a reproduction for you, but it's quite large monorepo with 103 projects inside
Does running nx graph
without options work?
Yes nx graph is working fine. If I do nx graph --file=./index.json it works as well, it's really specific to the html output
Interesting, and --file=output.json
works as well, just HTML is broken?
Yes --file=output.json
is working fine, just the HTML output seems broken. The json is generated in 0.80s, the HTML takes minutes and then crash.
Hi @jaysoo I have the same problem, in my case too my monorepo have more than 100 projects, I can easily generate the json output, but when I try to generate the html output it fails and timeout with the same error message.
If we share with you the json output, would it allow you to try the thing in your side?
RangeError: Invalid string length
at JSON.stringify (<anonymous>)
at buildEnvironmentJs (/node_modules/nx/src/command-line/graph/graph.js:74:70)
at Object.generateGraph (/node_modules/nx/src/command-line/graph/graph.js:223:35)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.handler (/node_modules/nx/src/command-line/graph/command-object.js:20:30)
The JSON is too big for json stringify, even when using an "optimized" version it still fail because the generated string is too big :
function JSONstringifyOptimized(obj) {
if (Array.isArray(obj)) {
return '[' +
obj.map( (value) => {
return JSONstringifyOptimized(value);
}).join(', ') +
']';
} else if (obj && typeof obj === 'object') {
return Object.keys(obj).length === 0
? '{}'
: '{' +
Object.keys(obj).map( (key) => {
return '"key"' + ': ' +
JSONstringifyOptimized(obj[key]);
}).join(', ') +
'}';
}
return obj;
}
function buildEnvironmentJs(exclude, watchMode, localMode, depGraphClientResponse, taskGraphClientResponse, expandedTaskInputsReponse, sourceMapsResponse) {
let environmentJs = `window.exclude = ${JSONstringifyOptimized(exclude)};
window.watch = ${!!watchMode};
window.environment = 'release';
window.localMode = '${localMode}';
window.appConfig = {
showDebugger: false,
showExperimentalFeatures: false,
workspaces: [
{
id: 'local',
label: 'local',
projectGraphUrl: 'project-graph.json',
taskGraphUrl: 'task-graph.json',
taskInputsUrl: 'task-inputs.json',
sourceMapsUrl: 'source-maps.json'
}
],
defaultWorkspaceId: 'local',
};
`;
if (localMode === 'build') {
environmentJs += `window.projectGraphResponse = ${JSONstringifyOptimized(depGraphClientResponse)};
`;
environmentJs += `window.taskGraphResponse = ${JSONstringifyOptimized(taskGraphClientResponse)};
`;
environmentJs += `window.expandedTaskInputsResponse = ${JSONstringifyOptimized(expandedTaskInputsReponse)};`;
environmentJs += `window.sourceMapsResponse = ${JSONstringifyOptimized(sourceMapsResponse)};`;
}
else {
environmentJs += `window.projectGraphResponse = null;`;
environmentJs += `window.taskGraphResponse = null;`;
environmentJs += `window.expandedTaskInputsResponse = null;`;
environmentJs += `window.sourceMapsResponse = null;`;
}
return environmentJs;
}
@jaysoo It might be caused by this commit https://github.com/nrwl/nx/commit/75cc561e9d28368c8f827ed62ba9f8f08fabff67 , now there is the source map displayed and it might be too big if you have a lot of project.
Hey!
I've tried reproducing the issue but interestingly haven't managed yet. For the record I've created a repo with over 550 projects & 70 targets each. The environment.js
that is generated was more than 230MB large.
Could you reproduce the error again and tell me exactly on which call is causing the issue? Is it the expandedTaskInputsReponse
or the sourceMapsResponse
? Then I can maybe repro it better myself.
Hey! Just checked and it fail at the JSON.stringify of the expandedTaskInputsReponse
Same issue for us too
Monrepo of +300 projects & 5-10 tasks per each & some 4 env for build
& serve
It's taking around 15 minutes to generate the object at createExpandedTaskInputResponse()
, then fail on the JSON.strigify()
for the window.expandedTaskInputsResponse
, with the same error:
RangeError: Invalid string length
at JSON.stringify (<anonymous>)
at buildEnvironmentJs (**/node_modules/nx/src/command-line/graph/graph.js:74:70)
at Object.generateGraph (**/node_modules/nx/src/command-line/graph/graph.js:223:35)
at async Object.handler (**/node_modules/nx/src/command-line/graph/command-object.js:20:30)
Only when using --file=*.html
local host and JSON are work fine
Current Behavior
When I try to execute the command yarn nx graph --file=./index.html I got this error :
Expected Behavior
The command should generate the html output. It works with json files.
GitHub Repo
No response
Steps to Reproduce
Nx Report
Failure Logs
Package Manager Version
No response
Operating System
Additional Information
No response