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