RangeError: Maximum call stack size exceeded
TL;DRThis JavaScript error occurs when a function calls itself (or a chain of functions calls) so many times without stopping that the browser or runtime runs out of space to track the calls.
Most likely cause: Infinite recursion in a function with no proper base case or exit condition
Try first: Open the browser or Node.js console and look at the stack trace
Likely causes
- Infinite recursion in a function with no proper base case or exit conditionmost likely
- Very deep but finite recursion that exceeds the engine's stack limitpossible
- Accidental self-referential data structures or event listeners that trigger each otherless likely
How to fix it
Safest first: SafeChanges settingsDangerous
Open the browser or Node.js console and look at the stack traceSafe
The error message usually shows the exact function and line that is calling itself repeatedly.
Add a base case or depth limit to any recursive function you recently changedChanges settings
Make sure every recursive function has a clear condition that stops further calls, such as checking if an array is empty or a counter has reached a limit.
Replace recursion with iteration (a loop) for the problematic function if possibleChanges settings
Loops use far less stack space than repeated function calls.
If that didn't fix it
Use a debugger to step through the function and watch how many times it calls itself before the error.
When to see a technician
If the error occurs inside a library or framework you did not write, ask the maintainers or a developer familiar with that code.
Quick answers
- What does RangeError: Maximum call stack size exceeded mean?
- This JavaScript error occurs when a function calls itself (or a chain of functions calls) so many times without stopping that the browser or runtime runs out of space to track the calls.
- What causes RangeError: Maximum call stack size exceeded?
- Infinite recursion in a function with no proper base case or exit condition. (most likely) Very deep but finite recursion that exceeds the engine's stack limit. (possible) Accidental self-referential data structures or event listeners that trigger each other. (less likely)
- How do I fix RangeError: Maximum call stack size exceeded?
- Try these in order, safest first: 1. Open the browser or Node.js console and look at the stack trace. 2. Add a base case or depth limit to any recursive function you recently changed. 3. Replace recursion with iteration (a loop) for the problematic function if possible.
- What if that didn't fix it?
- Use a debugger to step through the function and watch how many times it calls itself before the error.
- When should I see a technician?
- If the error occurs inside a library or framework you did not write, ask the maintainers or a developer familiar with that code.
Related errors
codeInvalid hook call. Hooks can only be called inside of the body of a function componentcodegyp ERR! find Python | gyp ERR! stack Error: Could not find any Python installation to usecodeFATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memorycodeUncaught ReferenceError: x is not definedcodeTypeError: "x" is not a functioncodeTypeError: can only concatenate str (not "int") to str