Skip to content
Latchkey

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
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

  1. Run nx graph to render dependencies and spot the loop.
  2. Break the import cycle by extracting shared code to a third library.
  3. Re-run so the graph becomes acyclic.
Terminal
nx graph --file=graph.html

Enforce no circular deps in lint

The module boundaries rule can flag circular dependencies so they fail lint before they overflow the graph.

.eslintrc.json
"@nx/enforce-module-boundaries": ["error", { "allowCircularSelfDependency": false }]

How to prevent it

  • Render nx graph in 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →