nx
nx copied to clipboard
RangeError: Maximum call stack size exceeded when trying to build (esbuild / tsc) apps with a large TS file
Current Behavior
When running nx build my-app-name I am encountering the following error.
> NX Maximum call stack size exceeded
Because of the error the Nx daemon process has exited. The next Nx command is going to restart the daemon process.
If the error persists, please run "nx reset".
{
stack: 'RangeError: Maximum call stack size exceeded\n' +
' at parseTypeOperatorOrHigher (somepath/node_modules/typescript/lib/typescript.js:34611:43)\n' +
' at parseUnionOrIntersectionType (somepath/node_modules/typescript/lib/typescript.js:34650:20)\n' +
' at parseIntersectionTypeOrHigher (somepath/node_modules/typescript/lib/typescript.js:34661:20)\n' +
' at parseUnionOrIntersectionType (somepath/node_modules/typescript/lib/typescript.js:34650:20)\n' +
' at parseUnionTypeOrHigher (somepath/node_modules/typescript/lib/typescript.js:34664:20)\n' +
' at parseType (somepath/node_modules/typescript/lib/typescript.js:34758:24)\n' +
' at parseListElement (somepath/node_modules/typescript/lib/typescript.js:33235:20)\n' +
' at parseDelimitedList (somepath/node_modules/typescript/lib/typescript.js:33539:34)\n' +
' at parseTypeArgumentsInExpression (somepath/node_modules/typescript/lib/typescript.js:36145:33)\n' +
' at speculationHelper (somepath/node_modules/typescript/lib/typescript.js:12434:26)',
message: 'Maximum call stack size exceeded\n' +
'\n' +
'Because of the error the Nx daemon process has exited. The next Nx command is going to restart the daemon process.\n' +
'If the error persists, please run "nx reset".'
}
Context:
- This is a brand new NX workspace with a single node Typescript application
- Build is using
esbuild - There is a single large TS file with ~28K lines
- You can reproduce this yourself by cloning https://github.com/dremonkey/nx-call-stack-exceeded-example
I have run a number of tests to see if this is a TS or NX problem. It seems to be a NX problem.
- I can use
tscandesbuildfrom the command line and both will complete successfully - If I disable the NX_DAEMON and increase the V8 stack size I can get the build to complete, i.e.
node --stack-size=5000 ./node_modules/.bin/nx build zxcv01 - I can build successfully using NX if the large TS file is removed
Expected Behavior
The build should work
GitHub Repo
https://github.com/dremonkey/nx-call-stack-exceeded-example
Steps to Reproduce
- Clone the repo
- Install dependencies
- Run
nx build zxcv01
Nx Report
Unable to run `nx report` because of the call stack exceeded error
Failure Logs
> NX Maximum call stack size exceeded
Because of the error the Nx daemon process has exited. The next Nx command is going to restart the daemon process.
If the error persists, please run "nx reset".
{
stack: 'RangeError: Maximum call stack size exceeded\n' +
' at parseTypeOperatorOrHigher (somepath/node_modules/typescript/lib/typescript.js:34611:43)\n' +
' at parseUnionOrIntersectionType (somepath/node_modules/typescript/lib/typescript.js:34650:20)\n' +
' at parseIntersectionTypeOrHigher (somepath/node_modules/typescript/lib/typescript.js:34661:20)\n' +
' at parseUnionOrIntersectionType (somepath/node_modules/typescript/lib/typescript.js:34650:20)\n' +
' at parseUnionTypeOrHigher (somepath/node_modules/typescript/lib/typescript.js:34664:20)\n' +
' at parseType (somepath/node_modules/typescript/lib/typescript.js:34758:24)\n' +
' at parseListElement (somepath/node_modules/typescript/lib/typescript.js:33235:20)\n' +
' at parseDelimitedList (somepath/node_modules/typescript/lib/typescript.js:33539:34)\n' +
' at parseTypeArgumentsInExpression (somepath/node_modules/typescript/lib/typescript.js:36145:33)\n' +
' at speculationHelper (somepath/node_modules/typescript/lib/typescript.js:12434:26)',
message: 'Maximum call stack size exceeded\n' +
'\n' +
'Because of the error the Nx daemon process has exited. The next Nx command is going to restart the daemon process.\n' +
'If the error persists, please run "nx reset".'
}
Additional Information
No response
We experience simillar issue (https://github.com/nrwl/nx/issues/14224) with print-affected task. The root cause seems to be our generated graphql.ts file, which is 150k LOC (yes, our schema is huge). It can be solved by either setting node --stack-size=10000 ./node_modules/.bin/nx or by listing the graphql.ts file in .nxignore.
tsc alone doesn't have any issues with typechecking so seems the problem might be in nx daemon.
thanks @belaczek , I have exactly the same issue, a giant graphql.ts file. Adding to .nxignore fixed the issue.
Does adding a file to nxignore exclude it from the affected builds?
We're having the same problem on version 16.4.2.
> nx run docent:build:production
Unable to read angular.json
RangeError: Failed to process the project graph with "nx-js-graph-plugin".
Maximum call stack size exceeded
at Object.scan (/app/node_modules/typescript/lib/typescript.js:10218:18)
at nextTokenWithoutCheck (/app/node_modules/typescript/lib/typescript.js:29151:42)
at createIdentifier (/app/node_modules/typescript/lib/typescript.js:29487:13)
at parseIdentifierName (/app/node_modules/typescript/lib/typescript.js:29522:18)
at parseEntityName (/app/node_modules/typescript/lib/typescript.js:30133:45)
at parseEntityNameOfTypeReference (/app/node_modules/typescript/lib/typescript.js:30301:18)
at parseTypeReference (/app/node_modules/typescript/lib/typescript.js:30316:15)
at parseNonArrayType (/app/node_modules/typescript/lib/typescript.js:31025:22)
at parsePostfixTypeOrHigher (/app/node_modules/typescript/lib/typescript.js:31086:22)
at doOutsideOfContext (/app/node_modules/typescript/lib/typescript.js:29051:18)
Adding the generated (graphql codegenerator) files to the .nxignore fixes the issue.
@DrewLandgraveCbsi
When a file is specified in the .nxignore file:
Changes to that file are not taken into account in the affected calculations.
Even if the file is outside an app or library, nx workspace-lint won't warn about it.
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.