Home·Error messages

node · JavaScript

The message

RangeError: Maximum call stack size exceeded

What it means

Calls piled up deeper than the engine allows, and it is usually not deep recursion but endless recursion. A function whose stopping condition is missing or never reached, two functions calling each other, JSON.stringify on an object that contains itself, or in React a render that sets the state it depends on. The stack in the console repeats two or three frames — that pair is the loop, and the base case belongs there. When the computation genuinely needs depth, rewriting the recursion as a loop or an explicit stack is the only route: you cannot raise the stack limit in a browser.

The fix

There is no one-line command for this. The explanation says what to look at instead.

Printed by
node
JavaScript
15

Browser and Node errors usually tell you what broke and not why the value became what it was — you read undefined, it was not a function, it was not JSON — so the place to fix is upstream of the line that threw, and silencing just that line with ?. and default values makes the same problem reappear further away in a form that is harder to recognise.

Reading an error message

  • Read from the first line down. The lower you go the more it is about the tool’s internals; the cause is usually at the top.
  • If there is a file and a line number, start there — not the top stack frame, but the topmost line that names a file you wrote.
  • Search the message verbatim, but strip your own paths and variable names first; those are what stop the search from matching.
  • The same condition is worded differently across tool versions. If results look wrong, add the version number to the query.
  • Before pasting a fix, check what it throws away. Some of these cannot be undone.

Common questions

Q. What does “RangeError: Maximum call stack size exceeded” mean?

Calls piled up deeper than the engine allows, and it is usually not deep recursion but endless recursion. A function whose stopping condition is missing or never reached, two functions calling each other, JSON.stringify on an object that contains itself, or in React a render that sets the state it depends on. The stack in the console repeats two or three frames — that pair is the loop, and the base case belongs there. When the computation genuinely needs depth, rewriting the recursion as a loop or an explicit stack is the only route: you cannot raise the stack limit in a browser.

Q. How do I fix it?

There is no one-line command. The explanation above says what to look at instead.

Q. Which tool prints this?

node. It sits under JavaScript, and the message runs to 6 words.

Errors nearby