Nx "Maximum call stack size exceeded" on project graph in CI
Nx traverses the project graph to order tasks. A cycle between projects (A depends on B depends on A) makes the traversal recurse indefinitely until the stack overflows with "Maximum call stack size exceeded".
What this error means
Nx crashes with "RangeError: Maximum call stack size exceeded" during project graph construction or task scheduling, not inside any single task.
NX Maximum call stack size exceeded
at createTaskGraph (.../nx/src/tasks-runner/...)Common causes
A circular dependency between projects
Two or more projects import each other, so the graph has a cycle and traversal never terminates.
A self-referential dependsOn chain
A dependsOn configuration creates a target-level cycle that recurses without a base case.
How to fix it
Find and break the cycle
- Run
nx graphto render dependencies and spot the loop. - Break the import cycle by extracting shared code to a third library.
- Re-run so the graph becomes acyclic.
nx graph --file=graph.htmlEnforce no circular deps in lint
The module boundaries rule can flag circular dependencies so they fail lint before they overflow the graph.
"@nx/enforce-module-boundaries": ["error", { "allowCircularSelfDependency": false }]How to prevent it
- Render
nx graphin review to catch new cycles. - Extract shared code into a leaf library instead of cross-importing.
- Enable the module boundaries lint rule to block cycles early.