node runtime_error ai_generated true

RangeError: Maximum call stack size exceeded

ID: node/maximum-call-stack

Also available as: JSON · Markdown
90%Fix Rate
90%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
20 active

Root Cause

Infinite recursion or deeply nested function calls. Common in recursive algorithms without base case.

generic

Workarounds

  1. 95% success Check recursive function for missing or incorrect base case
    Check recursive function for missing or incorrect base case

    Sources: https://developer.mozilla.org/en-US/docs/Glossary/Recursion

  2. 90% success Convert recursive algorithm to iterative with explicit stack
    const stack = [initial]; while (stack.length) { const item = stack.pop(); ... }

    Sources: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration

  3. 85% success Check for circular references in objects being JSON.stringify'd or deep-cloned
    Check for circular references in objects being JSON.stringify'd or deep-cloned

    Sources: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

Dead Ends

Common approaches that don't work:

  1. Increase Node stack size with --stack-size 80% fail

    Just delays the crash — infinite recursion will still overflow

  2. Convert to setImmediate/setTimeout recursion 60% fail

    May work but creates memory leaks and is very slow

Error Chain

Frequently confused with: