ProjectStack
npm

RangeError: Maximum call stack size exceeded

A function is calling itself (or a chain of functions is calling each other) infinitely without a stopping condition. This is a stack overflow — Node.js hits its call stack limit and crashes.

Common causes

  • A recursive function is missing its base case (the condition that stops the recursion)
  • Two functions are calling each other in an infinite loop
  • JSON.stringify is called on an object that contains circular references
  • An event handler is accidentally triggering itself

How to fix it

  1. Review your recursive function and make sure it has a valid base case that terminates the recursion
  2. For circular JSON: use JSON.stringify with a replacer, or use the 'flatted' package
  3. Add logging at the top of the recursive function to trace how deep it goes
  4. Consider converting deep recursion to an iterative loop with an explicit stack

Example

RangeError: Maximum call stack size exceeded at factorial (/home/user/app.js:3:10) at factorial (/home/user/app.js:5:12) at factorial (/home/user/app.js:5:12)

A recursive factorial function called with a negative number — the base case is never reached

Have a different error?

Paste any error message into the Error Translator to get an instant explanation.