Home › npm & Node.js

npm ERR! Maximum call stack size exceeded — how to fix

npm ERR! Maximum call stack size exceeded

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/me/.npm/_logs/2026-12-03T10_12_44_123Z-debug-0.log

Quick fix: Delete the install state and reinstall: rm -rf node_modules package-lock.json && npm cache verify && npm install. If it persists, update npm (npm install -g npm@latest) and look for a package that depends on itself or a file: link pointing at its own project.

What it means

Maximum call stack size exceeded is a JavaScript RangeError: some function recursed too deeply. When npm prints it as npm ERR! during install, ci or update, the recursion is inside npm's dependency-tree code (Arborist), not in your app. Something in the tree it is building makes the walk loop or go absurdly deep.

If the error comes from npm run <script> instead, the overflow is in the script you ran; see the RangeError page.

Fix 1: rebuild node_modules and the lockfile

A half-finished install, a merge conflict resolved badly in package-lock.json, or a lockfile from a very different npm version is the usual cause.

rm -rf node_modules package-lock.json
npm cache verify
npm install

On Windows PowerShell:

Remove-Item -Recurse -Force node_modules, package-lock.json
npm cache verify
npm install

Deleting the lockfile allows versions to move within your semver ranges. If you need exact versions, first try deleting only node_modules and running npm ci; only regenerate the lock if that fails, then review the diff.

Fix 2: clear a corrupted cache

npm cache verify repairs most problems. If the error persists:

npm cache clean --force
npm install

Fix 3: update npm and Node.js

Several npm releases had bugs where specific dependency graphs (peer dependency cycles, deeply nested overrides) blew the stack. Upgrade npm:

npm --version
npm install -g npm@latest

npm@latest can require a newer Node.js than you have; if it refuses, upgrade Node (for example with nvm install --lts), which bundles a recent npm.

Fix 4: a package that depends on itself

Check whether package.json lists its own name as a dependency, which happens after running npm install <name> inside the package called <name>:

{
  "name": "my-lib",
  "dependencies": {
    "my-lib": "^1.0.0"
  }
}

Remove that line. Similar loops come from file: or link: dependencies that point at the project itself or at each other in a cycle, e.g. "my-lib": "file:.". In a monorepo, check workspace packages for circular references.

Fix 5: problematic .npmrc or global packages

A prefix in ~/.npmrc that points inside the project, or a project-level .npmrc with unusual settings, can make npm walk into its own directories. Inspect the effective config:

npm config list

Temporarily move ~/.npmrc aside to test.

Find where it recurses

The debug log path is printed with the error. Its last lines before the error show which package npm was processing:

tail -n 60 ~/.npm/_logs/*-debug-0.log

A package name repeating over and over points to the loop. You can also run npm install --loglevel verbose to watch it live.

Last updated 2026-12-03.