JavaScript Error

Fix: RangeError: Maximum call stack size exceeded

By Samrat•Last updated: Nov 2026

Exact message

RangeError: Maximum call stack size exceeded

Quick answer

This error occurs when a function calls itself (directly or indirectly) without a proper exit condition, causing infinite recursion. It can also happen if you accidentally cause infinite state updates in React.

🛠️ Fix it right here with AI Code Explainer

Edit the traceback below if needed, then let our AI suggest a fix without leaving this page.

AI suggestions can be wrong. Review and test before applying.

Why this error happens

Every function call adds a frame to the call stack. Infinite recursion (missing base case) exhausts this stack, throwing a RangeError.

Example: Wrong vs Right

Wrong

function countDown(n) {
  console.log(n);
  countDown(n - 1); // No base case!
}

Right

function countDown(n) {
  if (n <= 0) return; // Base case
  console.log(n);
  countDown(n - 1);
}

How to fix it (step by step)

  1. Look for a recursive function in the stack trace
  2. Add a base case that stops the recursion
  3. If you are using React, check for a useEffect that updates state without a proper dependency array
  4. For deeply nested data, use an iterative approach (loops)

Frequently asked questions

How do I know if it's React causing this?

In React, this often presents as 'Maximum update depth exceeded'. It means a useEffect is triggering a state update that triggers the effect again.

Can I increase the stack size?

Node.js allows --stack-size=2000. However, in browsers, you cannot change it.

Related Search Terms

maximum call stack size exceededrangeerror call stackinfinite loop javascriptrecursion error

Related JS errors

Need to fix JS code not just errors?

Use the free to paste any JS snippet and get a line-by-line explanation.

Want an AI with memory for your project?

MonsterX AI remembers your codebase across chats.