ChatGPT解决这个技术问题 Extra ChatGPT

Maximum call stack size exceeded on npm install

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.

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.
Updated to v6.9.1 still got same error and updated question also. Thanks anyway TheEnvironmentalist
Some advice around here github.com/npm/npm/issues/10776
im my case, this was caused due to a recursive declaraion in package.json ;)
in my case, it was caused because I had lost internet connection

G
G-Ram

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

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
@MetaGuru please explain what are the consequences of running this command...
@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 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: 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.
TLDR; it will actually delete the cache like it's supposed to. Later dependency installs might go slower until re-cached.
J
João Marcos Gris

npm rebuild it has solved my problem


Can anyone explain this answer further? Why does this solve the problem?
deleted package-lock.json and npm rebuild did the trick for me
in my case, certain files in my .npm folder were installed as root. npm cache verify tells you what is wrong.
This did the trick. npm cache clean did not work on this occasion.
from the official docs: > This command runs the npm build command on the matched folders. This is useful when you install a new version of node, and must recompile all your C++ addons with the new binary.
b
bobbyz

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

rm package-lock.json
rm -r node_modules

You're killing the purpose of package-lock.json if you delete it. It guarantees that your dependencies will be deterministic.
True, but if you can't install your app on say a different platform, then you have no choice but to do this.
npm install should restore the package-lock.json file anyway
FWIW, these commands should be run inside your functions folder. I made the mistake of running it in the root folder
@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.
M
Michael Mior
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

Deleting the package-lock.json file fixed it for me, Thanks!
I sure hope you know what you are doing.
You don't have to do. @Ibrahimshamma
This one helped me too, Thanks
R
Rene Knop

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.


K
Kesav Sundar M

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


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."
G
Gopi P

npm rebuild will work for sure


What does this do and how does it solve the problem?
A
AvantContra

In my case, update to the newest version:

npm install -g npm


U
Umair Khalid

I deleted

node_modules

and then reinstalled by

npm install

It worked for me


funny enough i had to restart ,my computer in addition to your steps for it to work, since i am working with wsl
This worked for me, but none of the other solutions did
@Avshalom THIS! For all people who run into this issue using WSL2!
A
Aravinda Meewalaarachchi

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

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 Delete your node_modules folder and package-lock.json file. Force clean the entire NPM cache by using following comand. npm cache clean --force Re-Install all the dependencies. npm install If above step didn't resolve your problem, try to re-install your dependencies after executing following command. npm rebuild


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.
M
Melchia

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.


M
MetaSean

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


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.
d
danieltan95

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 /.


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.
I had WORKDIR / at the top but it seems doing an npm i or npm ci from / blows things up.
@PaulRobello yep, the folder has to be separate from the original, lemme edit the answer to be clearer.
M
Michael Mior

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.


Closing the editor fixed it for me. (Netbeans for me)
n
naorz

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.


p
pavlkara1

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.


w
wolfyuk

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.


G
Gajendra K S

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


j
jjmerelo

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.


j
jaihind

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.


C
Caleb Spindler

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.


R
Rajashekhar Reddy

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


H
Hidayat Arghandabi

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


J
Joshua Barker

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...


J
Jeff Hampton

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!


S
Shrivathsa

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>.


S
Spixz

I don't know why, but I ran npm install with sudo and it worked.

sudo npm install

F
Finchy70

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.


b
bildungsroman

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!


v
vgaltes

Switching to yarn solved the issue for me.