RangeError: Maximum call stack size exceeded

Node.js · updated 2026-11-05

Thrown when the V8 call stack fills up. The stack trace repeats the same one or two frames over and over; those repeating frames are the recursion you need to fix.

/app/src/models/user.js:9
  set email(value) {
           ^

RangeError: Maximum call stack size exceeded
    at User.set email (/app/src/models/user.js:9:12)
    at User.set email (/app/src/models/user.js:10:16)
    at User.set email (/app/src/models/user.js:10:16)
    at User.set email (/app/src/models/user.js:10:16)
    at User.set email (/app/src/models/user.js:10:16)

Quick fix

Read the repeating frames in the trace: they name the function that keeps calling itself. Add or correct the condition that stops the recursion, and if the data is legitimately deep (large trees, long linked lists), switch to an iterative loop with an explicit stack array instead of raising Node's stack size.

  1. Find the frames that repeat in the stack trace.
  2. Check that every recursive path reaches a stop condition.
  3. Look for setters, getters or toJSON methods that call themselves through this.
  4. Replace spreading huge arrays into function arguments with a plain loop.
  5. For deep data, rewrite the recursion as a while loop over an array.
typescript
// Recursive version overflows on very deep trees:
// function walk(node) { visit(node); node.children.forEach(walk); }

function walk(root: TreeNode) {
  const stack: TreeNode[] = [root];
  while (stack.length > 0) {
    const node = stack.pop()!;
    visit(node);
    for (const child of [...node.children].reverse()) stack.push(child);
  }
}
Fix it with your coding agent

Paste this into Claude Code, Cursor or Codex in the project that throws it. The agent reads this guide in plain text and applies the fix that matches your stack.

prompttext
Read https://runheed.com/errors/maximum-call-stack-size-exceeded.md and fix this error in this project.

Why it happens

Missing or unreachable base case

The stop condition never becomes true: an off-by-one, a comparison against the wrong field, or input that skips the case the author expected (an empty string instead of null, a negative number).

Accessor that calls itself

set email(value) { this.email = value } assigns through the setter again, forever. A getter that reads its own property, or a Proxy get trap that reads from the proxy, loops the same way. Store the value in a separate field such as #email.

Spreading a huge array into arguments

Math.max(...values) and target.push(...items) pass every element as a separate argument. With very large arrays the arguments alone overflow the stack even though nothing is recursive; the exact size that breaks depends on the engine.

Walking circular data without tracking visits

Hand-written deepClone, deepEqual or serializers follow parent pointers or ORM relations in a loop with no visited set. JSON.stringify detects cycles itself, but custom recursive code does not.

Event or update ping-pong

A listener emits the event it listens to, or two pieces of state update each other synchronously (a change handler writes back to its source, which fires the handler again).

Other fixes

  • Use structuredClone for deep copies; it handles circular references.
  • Compute max or min over large arrays with reduce or a for loop instead of spread.
  • Track visited objects in a WeakSet when traversing graphs that may contain cycles.
  • Raising the limit with node --stack-size is for diagnosis only; values set too high can segfault the process.

Same error, other wording

  • Uncaught RangeError: Maximum call stack size exceeded
  • RangeError: Maximum call stack size exceeded.
  • InternalError: too much recursion

Let your coding agent catch the next one

Runheed records this error in production with the stack trace, the breadcrumbs before it and, when you set it, the agent session that shipped the code, and serves it to Claude Code, Cursor or any MCP client. With it connected, you can ask:

> Find the "Maximum call stack size exceeded" errors in production, identify the repeating function in the stack, and fix its base case or rewrite it iteratively.

Setup for Node.js and Express or Vercel Functions, then have your agent fix and resolve it.

Related errors

More in Memory, async and the process

Other error topics

Free tools: Source map stack trace decoder · Uptime and SLA downtime calculator · Error budget calculator · Stack trace formatter · JSON log viewer · HTTP status code reference.

References: MDN: InternalError: too much recursion, MDN: structuredClone()

Spotted a mistake? Email hello@greatwork.company. About Runheed.