Node "Maximum call stack size exceeded" in CI - Fix Runaway Recursion
This RangeError means the call stack overflowed, almost always from unbounded recursion or a cyclic call chain that never reaches a base case.
What this error means
A node process throws RangeError: Maximum call stack size exceeded with a stack trace that repeats the same function, then exits non-zero.
node
RangeError: Maximum call stack size exceeded
at serialize (/home/runner/work/app/app/src/serialize.js:4:18)
at serialize (/home/runner/work/app/app/src/serialize.js:7:12)
at serialize (/home/runner/work/app/app/src/serialize.js:7:12)Common causes
Recursion with no reachable base case
A recursive function never satisfies its termination condition, so it calls itself until the stack overflows.
A circular reference during traversal or serialization
An object graph with a cycle drives a recursive walk into an infinite loop.
How to fix it
Add or fix the base case
- Identify the repeating frame in the stack trace.
- Add the termination condition so recursion stops.
JavaScript
function walk(node) {
if (!node) return;
walk(node.next);
}Track visited nodes to break cycles
- Keep a visited set during traversal.
- Skip nodes already seen so a cycle cannot recurse forever.
JavaScript
function walk(node, seen = new Set()) {
if (!node || seen.has(node)) return;
seen.add(node);
walk(node.next, seen);
}How to prevent it
- Always define a reachable base case, guard traversals against cycles, and convert very deep recursion to iteration so input size cannot blow the stack in CI.
Related guides
Node "Cannot read properties of undefined (reading X)" in CI - Fix the Null AccessFix the Node.js "Cannot read properties of undefined (reading X)" TypeError in CI by guarding the access or e…
Node "TypeError: X is not a function" in CI - Fix the Bad CallFix the Node.js "TypeError: X is not a function" in CI by correcting a bad import shape, a missing method, or…
Node AssertionError in CI - Fix the Failed InvariantFix the Node.js AssertionError in CI by correcting the value that violates the assertion or fixing the assert…