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.
- Find the frames that repeat in the stack trace.
- Check that every recursive path reaches a stop condition.
- Look for setters, getters or toJSON methods that call themselves through this.
- Replace spreading huge arrays into function arguments with a plain loop.
- For deep data, rewrite the recursion as a while loop over an array.
// 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);
}
}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.
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
- FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
- TypeError: Cannot read properties of undefined (reading 'x')
- [UnhandledPromiseRejection: This error originated either by throwing inside of an async...
More in Memory, async and the process
- RecursionError: maximum recursion depth exceededPython
- RuntimeError: Event loop is closedPython
- RuntimeWarning: coroutine 'fetch_user' was never awaitedPython
- Error: listen EADDRINUSE: address already in use :::3000Node.js
- OSError: [Errno 98] Address already in usePython
- Error: error:0308010C:digital envelope routines::unsupportedNode.js
- MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error...Node.js
- Error: ENOENT: no such file or directory, open '/app/config.json'Node.js
- Error: EACCES: permission denied, open '/app/data/cache.json'Node.js
- Error: EMFILE: too many open files, open '/app/uploads/0412.jpg'Node.js
- PermissionError: [Errno 13] Permission denied: '/app/data/report.csv'Python
- CredentialsProviderError: Could not load credentials from any providersNode.js
- botocore.exceptions.NoCredentialsError: Unable to locate credentialsPython
- django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.Python
Other error topics
- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer...Network and HTTP
- Error: connect ECONNREFUSED 127.0.0.1:5432Network and HTTP
- AxiosError: Request failed with status code 401Network and HTTP
- error: null value in column "total" of relation "orders" violates not-null constraintDatabases
- PrismaClientKnownRequestError: Unique constraint failed on the fields: (`email`)Databases
- error: new row violates row-level security policy for table "todos"Databases
- Module not found: Can't resolve 'fs'Imports and modules
- AttributeError: module 'requests' has no attribute 'get'Imports and modules
- TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /app/src/index.tsImports and modules
- You're importing a module that depends on `useState` into a React Server Component...React and Next.js rendering
- An error occurred in the Server Components render. The specific message is omitted in...React and Next.js rendering
- Error: NextRouter was not mounted.React and Next.js rendering
- KeyError: 'email'Undefined, None and type errors
- TypeError: 'str' object is not callableUndefined, None and type errors
- TypeError: items is not iterableUndefined, None and type errors
- pydantic_core._pydantic_core.ValidationError: 1 validation error for User email Field...JSON, parsing and validation
- SyntaxError: Unexpected end of JSON inputJSON, parsing and validation
- RangeError: Invalid time valueJSON, parsing and validation
- Error executing tool get_orderMCP servers and clients
- McpError: MCP error -32001: Request timed outMCP servers and clients
- Bad Request: No valid session ID providedMCP servers and clients
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.