293

I'm trying to run npm install, this is output from console:

npm ERR! Linux 4.8.0-27-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! node v6.9.1
npm ERR! npm  v3.10.8

npm ERR! Maximum call stack size exceeded
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

and this is content of npm-debug.log:

113791 verbose stack RangeError: Maximum call stack size exceeded
113791 verbose stack     at Object.color (/usr/lib/node_modules/npm/node_modules/npmlog/node_modules/console-control-strings/index.js:115:32)
113791 verbose stack     at EventEmitter.log._format (/usr/lib/node_modules/npm/node_modules/npmlog/log.js:252:51)
113791 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npmlog/log.js:138:24)
113791 verbose stack     at emitThree (events.js:116:13)
113791 verbose stack     at emit (events.js:194:7)
113791 verbose stack     at .<anonymous> (/usr/lib/node_modules/npm/node_modules/npmlog/node_modules/are-we-there-yet/tracker-group.js:23:18)
113791 verbose stack     at emitThree (events.js:116:13)
113791 verbose stack     at emit (events.js:194:7)
113791 verbose stack     at .<anonymous> (/usr/lib/node_modules/npm/node_modules/npmlog/node_modules/are-we-there-yet/tracker-group.js:23:18)
113791 verbose stack     at emitThree (events.js:116:13)
113791 verbose stack     at emit (events.js:194:7)
113792 verbose cwd /home/giorgi/AdMove/dev/web-advertiser-admove
113793 error Linux 4.8.0-27-generic
113794 error argv "/usr/bin/nodejs" "/usr/bin/npm" "install"
113795 error node v6.9.1
113796 error npm  v3.10.8
113797 error Maximum call stack size exceeded
113798 error If you need help, you may report this error at:
113798 error     <https://github.com/npm/npm/issues>
113799 verbose exit [ 1, true ]

Removed node_modules several times and tried to reinstall. Can't understand what's the reason that causes this and how to fix it.

GROX13
  • 4,605
  • 4
  • 27
  • 41
  • 1
    First of all, I'd check the github issues link for similar problems, and add it if it's not a known problem. Also, why are you trying to install v4.2.6? The current latest build is v7.1.0, and the recommended stable build is v6.9.1. Clear everything out, try 6.9.1, and update the question. – TheEnvironmentalist Nov 12 '16 at 18:44
  • 2
    Updated to v6.9.1 still got same error and updated question also. Thanks anyway [TheEnvironmentalist](http://stackoverflow.com/users/2480092/theenvironmentalist) – GROX13 Nov 12 '16 at 18:58
  • 1
    Some advice around here https://github.com/npm/npm/issues/10776 – Boris Charpentier Nov 12 '16 at 19:11
  • 2
    im my case, this was caused due to a recursive declaraion in package.json ;) – Alberto S. Mar 06 '20 at 09:14
  • 3
    in my case, it was caused because I had lost internet connection – RayJ_inSJ May 15 '20 at 21:07
  • This is why I hate Node – Bawantha Jan 04 '23 at 08:59

44 Answers44

178

metzelder's answer helped me fix the issue. however if you run the command npm cache clean, it will give you a message

As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid

So, as of npm5 you can do by adding a --force flag to the command.

So the command is:

npm cache clean --force
G-Ram
  • 33
  • 3
  • 6
codingbruh
  • 2,263
  • 1
  • 13
  • 14
  • On a *Node v10.15.1* and *npm 6.4.1* environment this worked like a charm! Thanks a lot. – Zeeng Apr 23 '19 at 11:15
  • 4
    As for me I had move the current working directory to another folder – seems like it mixed up npm. Deleting node_modules and reinstalling did the trick – Philippe Hebert Jun 11 '19 at 21:42
  • 21
    @MetaGuru please explain what are the consequences of running this command... – cdalxndr Mar 03 '20 at 16:28
  • @cdalxndr it's a joke since that's what the command says when you use the `--force` flag. ie: `npm WARN using --force I sure hope you know what you are doing.` – CTS_AE Apr 20 '20 at 12:35
  • 6
    @CTS_AE I don't think the npm team added that message as a joke. There must be a consequence and someone should explain it. – cdalxndr Apr 20 '20 at 15:45
  • 4
    @cdalxndr I was saying that it is left as a comment as a joke/satire, as a direct quote from `npm` he wasn't really adding anything helpful, but more of a meme at this point. You can read more about the actual command here: https://docs.npmjs.com/cli-commands/cache.html it explicitly explains what force does; that all cache items are now fully verified for their integrity, if something is corrupt it will self heal, thus the cache should always be in a proper state and never cleared unless you're trying to reclaim disk space, thus you will need to append `--force`. Note: May vary per version. – CTS_AE Apr 20 '20 at 21:45
  • 3
    TLDR; it will actually delete the cache like it's supposed to. Later dependency installs might go slower until re-cached. – CTS_AE Apr 20 '20 at 22:03
  • Seems I had to do an update to npm with `npm i -g npm` then run this `npm cache clean --force` now I can finally run `npm i` – CTS_AE Apr 20 '20 at 22:07
  • npm suggests running `npm install --cache /tmp/empty-cache` to run with a temporary empty cache rather than deleting the real one. I would try this to see if it solves the problem before running `npm cache clean --force` – kat Apr 23 '21 at 13:57
  • 1
    I did that with the same bad result, what did the trick for me was to update npm to the latest stable version. – Pepe Alvarez Aug 24 '21 at 17:37
145

npm rebuild it has solved my problem

YYY
  • 3,440
  • 5
  • 20
  • 24
96

Try removing package-lock.json and the node_modules folder:

rm package-lock.json
rm -r node_modules
bobbyz
  • 4,946
  • 3
  • 31
  • 42
Marat Zimnurov
  • 1,462
  • 9
  • 15
  • 33
    You're killing the purpose of package-lock.json if you delete it. It guarantees that your dependencies will be deterministic. – Eliseu Monar dos Santos Aug 12 '19 at 02:16
  • 14
    True, but if you can't install your app on say a different platform, then you have no choice but to do this. – Marc Oct 12 '19 at 07:42
  • 4
    `npm install` should restore the `package-lock.json` file anyway – kip2 Sep 03 '20 at 20:46
  • FWIW, these commands should be run inside your `functions` folder. I made the mistake of running it in the root folder – kip2 Oct 15 '20 at 11:04
  • 5
    @kip2 It will produce a new `package-lock.json`, but not necessarily the same one as new versions of dependencies may be available since it was last created. It's possible that one of these new versions could break things. – Michael Mior Dec 14 '20 at 20:24
  • @kip2 where can we read about `functions` folder, never heard of it :) – Maxim V. Pavlov Mar 07 '21 at 11:44
  • @MaximV.Pavlov here's the link: https://firebase.google.com/docs/functions/manage-functions#deploy_functions. In particular, note: _By default, the Firebase CLI looks in the functions/ folder for the source code. You can specify another folder by adding the following lines in firebase.json_: "functions": { "source": "another-folder" } – kip2 Mar 08 '21 at 03:32
29

I had the same issue with npm install. After a lot of search, I found out that removing your .npmrc file or its content (found at %USERPROFILE%/.npmrc), will solve this issue. This worked for me.

Rene Knop
  • 1,788
  • 3
  • 15
  • 27
Arwa S k
  • 316
  • 3
  • 7
28
npm uninstall

npm cache clean --force

I tried these two methods but they didn't work. After, I deleted the node_modules directory and ran npm install again, it still didn't work. Lastly, I deleted package-lock.json and created a new package-lock.json file using

npm install
Michael Mior
  • 28,107
  • 9
  • 89
  • 113
Kerim Kuşcu
  • 417
  • 4
  • 12
21

I have overcome this issue by doing following:

  • Delete all the content of the npm dependencies. You can find the default install location according to this thread: https://stackoverflow.com/a/5926706/1850297

  • Before you run npm install command, I suggest to run npm cache clean --force

metzelder
  • 655
  • 2
  • 15
  • 35
  • Message from `npm cache clean`: "As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid." – Ian Grainger Jul 03 '18 at 08:57
17

npm rebuild will work for sure

Gopi P
  • 525
  • 9
  • 19
  • 4
    What does this do and how does it solve the problem? – Menasheh Jun 23 '21 at 22:04
  • "for sure" might be a little strong – Nick Manning Aug 31 '22 at 19:51
  • @Menasheh npm install will install all packages and its dependencies from package json file and build it. if any dependent build failed then npm install won't stop, instead it get succeeded. but in the case of npm rebuild, it uses when you upgrade the node version and this command will rebuild the c++ addon from the beginning I mean new binary so it fixes the issue. even after this if the issue did not fix then delete package-lock file and try – Gopi P Sep 09 '22 at 14:35
  • @Menasheh note npm rebuild fail when any dependent addon build failure also – Gopi P Sep 09 '22 at 14:38
16

In my case, update to the newest version:

npm install -g npm

AvantContra
  • 371
  • 1
  • 3
  • 10
13

I deleted

node_modules

and then reinstalled by

npm install

It worked for me

Umair Khalid
  • 2,259
  • 1
  • 21
  • 28
11

I have also faced the same problem and this is how i resolved it.

  1. First of all you need to make sure that your node and npm versions are up to date. if not please upgrade your node and npm packages to latest versions.

    nvm install 12.18.3 // update node version through node version manager
    
    npm install npm // update your npm version to latest
    
  2. Delete your node_modules folder and package-lock.json file.

  3. Force clean the entire NPM cache by using following comand.

    npm cache clean --force
    
  4. Re-Install all the dependencies.

    npm install
    
  5. If above step didn't resolve your problem, try to re-install your dependencies after executing following command.

    npm rebuild
    
Aravinda Meewalaarachchi
  • 2,551
  • 1
  • 27
  • 24
  • I am unable to delete node_modules. I've had this occur twice. First time I had to `npm eject`, but I still had a few folders I could never remove `common-tags`, `react-dev-utils`, and `stream-browserify`. – Inarus Lynx Mar 18 '21 at 13:03
6

This issue can also happen if you're trying to install a package that doesn't exist or if you're trying to install a version that doesn't exist.

Melchia
  • 22,578
  • 22
  • 103
  • 117
5

npm cache clean returns below message

As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead. On the other hand, if you're debugging an issue with the installer, you can use npm install --cache /tmp/empty-cache to use a temporary cache instead of nuking the actual one.

If you run npm cache verify, as specified above, then it actually runs cache verification and garbage collection which fixes the problem.

Cache verified and compressed (~\AppData\Roaming\npm-cache_cacache): Content verified: 6183 (447214684 bytes) Content garbage-collected: 16 (653745 bytes) Index entries: 9633

MetaSean
  • 881
  • 17
  • 25
Synster
  • 329
  • 6
  • 16
  • This was enough for me. npm cache verify fixed the issue in a way that removing node_modules didn't. (And I wasn't going to nuke the cache or package-lock.json). Pretty sure this is an issue with npm, though. Can't see why npm cache verify would change anything if it truly did self-heal. – Stuart Watt Mar 05 '20 at 15:19
4

In case none of these answer work for you, it may be because the terminal you're using isn't the right one/ your node_modules is used by another part of your computer.

In my case I kept juggling between this error (maximum call stack size exceeded) and the access error event when I did a sudo npm i.

The fix was to close my IDE (which was WebStorm), run npm i in a basic terminal, and that was it.

Michael Mior
  • 28,107
  • 9
  • 89
  • 113
Jonathan Simonney
  • 585
  • 1
  • 11
  • 25
4

Happened in docker (node:15-buster) for me.

Remember to use WORKDIR /<folder> so that it doesn't conflict with original npm libraries installed.

The folder can be anything but system folders, so that includes using /.

danieltan95
  • 810
  • 7
  • 14
  • I had the "call stack size exceeded" issue in docker until I moved the WORKDIR line to near the top of the Dockerfile. Apparently the location of that line matters. – zipzit Nov 07 '20 at 07:53
  • I had `WORKDIR /` at the top but it seems doing an `npm i` or `npm ci` from `/` blows things up. – Paul Robello Nov 13 '20 at 01:24
  • @PaulRobello yep, the folder has to be separate from the original, lemme edit the answer to be clearer. – danieltan95 Nov 14 '20 at 15:18
3

I'm not a Windows user, so if you are, try to check Rene Knop comment.

For Unix/OSX users, I've removed the root .npmrc file ~/.npmrc.
Before you're going to try it, please, check if there is nothing necessary over there you can use this command to bring all content into your terminal: cat ~/.npmrc .

If you have got something like:

cat: /Users/$USER/.npmrc: No such file or directory

to save a copy:

cp ~/.npmrc ~/.npmrc_copy

Now, try to remove it (Works for bash users: Unix / Ubuntu / OSX ...):

rm -f ~/.npmrc

This worked for me.
Hope this will be helpful for others.

naorz
  • 349
  • 3
  • 6
3

I also had the same problem. I had tried the previous solutions, but the solution for me was much simpler. I only had to remove the space in the directory and then run npm i again

Thanks to: https://github.com/nodejs/node-gyp/issues/809#issuecomment-155019383 for pointing this out.

pavlkara1
  • 160
  • 2
  • 12
3

In my case I had a custom .npmrc file that included an auth token for authenticating with a private npm registry.

The token had expired, which helpfully returned code E401: Incorrect or missing password locally, but ERR! Maximum call stack size exceeded from the CI build.

wolfyuk
  • 746
  • 1
  • 8
  • 26
3

TLDR

For those of you using NVM, make sure you're using the right version of Node & NPM!

Background

I started getting this error after I started using NVM for a different project. When I went to run npm install on a project for my work, I got this error stating that the maximum call stack size had been exceeded.

This turned out to be caused by me using Node 12 and its accompanying NPM version while I should've been using Node 16.

Solution

Switch to a more recent version of Node & NPM;
nvm use <version> (for example, nvm use 16)

Tess E. Duursma
  • 186
  • 1
  • 8
2

You uninstall npm package and force clean the cache and close terminal and reinstall whichever package be.

$sudo npm uninstall <package - name>
$sudo npm cache clean --force

Then restart terminal and check

Still not working upgrade both npm and node to the latest version

Gajendra K S
  • 117
  • 1
  • 5
2

Today we encountered this error when running an npm prune even after running an npm cache clean --force.

Versions:

node 13.8.0 
npm 6.13.6

Deleting the package-lock.json worked for this case as well. Thank you all!

2

In general, once a module has been installed, it's much more convenient to use npm ci instead of npm install. Please check out this SO answer for the advantages of the former with respect to the later in a production environment. So please just run

npm ci

All dependencies will be updated, and the problem will disappear. Or it will error in the case there's some grave de-synchronization between one and the other.

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
2

Most of the times, this issue occurs if you are using the system provided by the organization you work for and it's vpn restricts the use of this command. In this case, you may try to disconnect from organization vpn and then execute this command.

jaihind
  • 1,090
  • 1
  • 8
  • 9
1

I tried everything to fix this issue on my Mac. I think the issue started when I had already downloaded npm from Node.js and then reinstalled it with Homebrew while following along with a Team Treehouse video.

Here's what I tried:

From https://docs.npmjs.com/misc/removing-npm

sudo npm uninstall npm -g
sudo make uninstall
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*

From How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}

Here's what worked:

In the end, the only thing that worked for me was to clone down the npm-reinstall repo from GitHub that completely removed everything related to npm on my Mac.

https://github.com/brock/node-reinstall

I then had to reinstall node and npm from Node.js.

1

I tried everything to fix this issue on my windows 7 machine like

Reinstalling and rebuilding npm

At last, I fixed this small configuration setting issue by wasting my entire day.

How I resolved this issue

Removing my project specific configurations in global .npmrc at location like drive:/Windows/Users/../.npmrc

1

I solved it 100% I had this problem with gulp version: 3.5.6.

You should clean the package-lock.js and then run npm install and It worked form

1

Our company dev environment uses Artifactory as the default registry for our NPM dependencies, and when running npm install it was defaulting to this, which did not work... so manually specifying the main npm registry via npm install --registry https://registry.npmjs.org fixed this issue for me...

Joshua Barker
  • 987
  • 2
  • 11
  • 23
1

I was facing the same error, I was trying to install jest into to one of the packages in a monorepo project.

If you are using Yarn + Learna to package a monorepo project, you will have to navigate to the package.json inside the target package and then run npm install or npm install <package name>.

Shrivathsa
  • 91
  • 6
0

I had this problem and it was due to an upgrade of my git executable. I rolled back to Git-2.21.0.rc1.windows.1-64-bit and added this to my environment path and it fixed my issue.

Finchy70
  • 441
  • 9
  • 25
0

The one thing that finally worked for me on Mac was upgrading from node 8.12 to 10.x using NVM.

I uninstalled all other versions of Node with NVM, then installed 10.x, then ran nvm alias default node, which tells NVM to always default to the latest available node version on a shell.

After that, my live reloading issue went away!

bildungsroman
  • 437
  • 1
  • 8
  • 17
0

Switching to yarn solved the issue for me.

vgaltes
  • 1,150
  • 11
  • 18
0

For those having this issue when building a Docker image with Jenkins (or any CI), make sure the package-lock.json is also copied to the container.

COPY ./src/package*.json /home/node/
RUN npm install

For us, the install actually went fine, the error only occurred when running npm prune production for the production image.

Adam Eri
  • 889
  • 7
  • 13
  • I have this problem with npm prune and NODE_ENV not set to production. Solved by removing node_modules and npm install again – Eduardo Mar 12 '20 at 23:21
0

If your default npm registry is something other than the public npm repository (you can check this by going to your .npmrc file or checking your npm config via npm CLI commands), you could try unsetting the registry config so it points back to the public npm repository. Then run npm install again.

If you have dependencies that aren't available in the public npm repository, try temporarily removing those dependencies from package.json. This will allow you to run npm install. Finally, revert the dependencies and registry config you removed and run npm install one last time to install the rest of your dependencies.

Xchai
  • 1,473
  • 1
  • 11
  • 10
0

I was facing a similar error. I tracked it down to the fact that npm was unable to delete files from the .bin folders for a npm link'd folder. So I went in and rm -rf all the .bin folders from the npm link'd folder.

find "linked-folder" -type d -name ".bin" -print  
For all folders listed | rm -rf  

That resolved the issue.

nishant
  • 736
  • 1
  • 12
  • 22
0

Following steps helped me to solve this issue:

  1. Stop all react strips (e.g. start build)
  2. run npm cache clean --force
  3. run npm install
ATQSHL
  • 381
  • 3
  • 12
0
echo 65536 | sudo tee -a /proc/sys/fs/inotify/max_user_watches

works for me on Ubuntu.

Dionis Oros
  • 664
  • 8
  • 12
0
npm cache clean --force

This works for me with node 8, and npm 6+

thedarkgriffen
  • 394
  • 3
  • 16
0

The error message may not be directly related to the npm procedure you are trying to run, it might be other node processes running that conflict or use up resources.

In my case I had an empty node_modules folder fresh from a recent init and still got

npm ERR! Maximum call stack size exceeded

when running npm install --save-dev @wordpress/scripts for WordPress plugin development.

The issue was a live reload watcher running in my wp-content folder, with that stopped the install worked first time.

CodeMonkey
  • 3,271
  • 25
  • 50
0

In my case Maximum call stack size exceeded was triggered by another error earlier. The logs looked like this:

// ... skipping some deprecation warnings

> core-js@3.6.5 postinstall /root/.nvm/versions/node/v14.10.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-graphql-types-generator/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

sh: 1: node: Permission denied
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/@aws-amplify/cli/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! Maximum call stack size exceeded

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-09-10T14_10_28_397Z-debug.log

Note sh: 1: node: Permission denied that led me to https://forum.vuejs.org/t/cannot-install-vue-cli-permission-error-in-require-postinstall/82017/7

I had to add --unsafe-perm to the install command and run it as root:

sudo npm install -g --unsafe-perm @aws-amplify/cli
thisismydesign
  • 21,553
  • 9
  • 123
  • 126
0

I had this problem and it turned out, I had a symbolic link inside node_modules pointing to it's parent, i.e.

[user@localhost]$ ls -la /path/to/project/node_modules
total 3272
...
lrwxrwxrwx   1 user user  50 Nov 26 18:38 node_modules -> ../node_modules
...

I mean, somehow I messed the bash script and it created a circular symbolic link. Removing the symbolic link solved the issue.

Kevin Kopf
  • 13,327
  • 14
  • 49
  • 66
0
rm -rf node_modules

and then reinstall worked for me.

note: probably don't need to rip out your lock files

Allen
  • 4,431
  • 2
  • 27
  • 39
0

Try this first!

Run npm install again

Crazily simple, but I don't know who else tried this so thought I should put it up here, despite all the existing answers. I suggest people try this first though, given it's the simplest solution and doesn't come with the risks others have noted when, say, deleting package-lock.json

Theory:

This is totally unproven as I'm just doing this to run a code screen (i.e. a totally new repo to me) and I guessed that some of the packages had been installed the first time npm install was run; it just ran out of resources later on.

I guessed that if I ran npm install again it would skip the install of the now-installed packages and complete, or at least get further. The behaviour I guessed at was what I saw but I didn't actually debug or test if this behaviour was for the reasons I guessed!

Clearly a lot of different things have worked for different people, but I thought I should add an answer to this already well-answered question on the basis it's the most trivial to do.

And if you're lucky it's going to run for long enough for you to grab a or ☕

Retne
  • 84
  • 1
  • 7
0

I tried all suggestions in this thread but none of them working, I keep getting RangeError: Maximum call stack size exceeded when I run 'npm install'. I decide to run npm start directly, and it start successfully whit no error...

KLMN
  • 529
  • 4
  • 13
0

delete your node_modules directory and package-lock.json files and reinstall your dependencies.

saeed eivazi
  • 818
  • 1
  • 7
  • 14
-1

I came across to same problem but in my case I have been using yarn from beginning but from some package readme I copied the npm install command and got this error. Later realised that yarn add <package-name> solved the issue and package was installed.

It might help someone in future.

necixy
  • 4,964
  • 5
  • 38
  • 54