85

I have a Node.js application. When I try to run npm install it hangs with this:

loadIdealTree:loadAllDepsIntoIdealTree: sill install loadIdealTree

npm install --verbose gives me a little extra info:

npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli   '/usr/local/bin/npm',
npm verb cli   'install',
npm verb cli   '--verbose',
npm verb cli   'aws-sdk-js' ]
npm info using [email protected]
npm info using [email protected]
npm verb npm-session ea38310110279de7
npm http fetch GET 404 https://registry.npmjs.org/aws-sdk-js 2211ms
npm verb stack Error: 404 Not Found: aws-sdk-js@latest
npm verb stack     at fetch.then.res (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/fetch.js:42:19)
npm verb stack     at tryCatcher (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
npm verb stack     at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:512:31)
npm verb stack     at Promise._settlePromise (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:569:18)
npm verb stack     at Promise._settlePromise0 (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:614:10)
npm verb stack     at Promise._settlePromises (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:693:18)
npm verb stack     at Async._drainQueue (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:133:16)
npm verb stack     at Async._drainQueues (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:143:10)
npm verb stack     at Immediate.Async.drainQueues (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:17:14)
npm verb stack     at runCallback (timers.js:789:20)
npm verb stack     at tryOnImmediate (timers.js:751:5)
npm verb stack     at processImmediate [as _immediateCallback] (timers.js:722:5)
npm verb cwd /Users/me/git/aws-sdk-js-perf
npm verb Darwin 17.5.0
npm verb argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "--verbose" "aws-sdk-js"
npm verb node v8.9.2
npm verb npm  v5.8.0
npm ERR! code E404
npm ERR! 404 Not Found: aws-sdk-js@latest
npm verb exit [ 1, true ]

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/me/.npm/_logs/2018-05-24T10_30_55_688Z-debug.log

I came across instances where other people experienced this but the below seemed to resolve their issue. It doesn't fix mine:

npm set registry http://registry.npmjs.org/

Does anybody know what might be wrong?

1
  • I have fix the issue: . I configure proxy for external access then it allow/bypass to install angular package. Check with your team to get .bat file and run it or set proxy manually. Jan 16 at 9:57

40 Answers 40

102

Had the same issue, and this comment here fixed it for me:

Try to remove 'package-lock.json' file from directory where 'package.json' locate.

6
  • 5
    Additionally I had to remove node_modules to make npm work again Sep 26, 2021 at 5:34
  • 5
    There was no 'package-lock.json' file , tried all the things nothing worked but npm config set strict-ssl false Apr 1, 2022 at 12:05
  • 3
    sigh... i do every all of this and still stucked ... deleting node_modules and package.json and runed npm config set strict-ssl false any other options?
    – Rman__
    Apr 7, 2022 at 19:19
  • 6
    I experienced this when I was on a vpn. I stopped the vpn and it worked.
    – Kip
    May 27, 2022 at 14:45
  • I experienced this when I wasnt on vpn... turns out some of the dependencies were local to my works servers only accessible via VPN Jan 23 at 17:45
32

Simply follow the following given steps:

  1. npm config set registry http://registry.npmjs.org/ --global
  2. npm cache clear --force
  3. Delete your package-lock.json file(it will automatically get created after npm i).
  4. Now try for npm install

This worked for me.

2
  • use registry.npmjs.org
    – Hunkoys
    Dec 8, 2021 at 18:48
  • verify your registry config after you do above change - npm config get registry
    – Hardik
    Feb 8 at 9:18
23

This problem happens also when you have a very slow connection

6
  • 1
    My stats are : ping=9ms download=40 MBPS download=3.9M BPS. I can watch a anime on the same browser with any problem :s
    – JRichardsz
    Apr 26, 2020 at 0:05
  • 1
    I just had this problem a few minutes ago. I can't be 100 percent sure, but I am pretty sure that switching to my phone's hotspot was the thing that fixed it. Also, the rest of the family are all gaming / streaming, so the network is under some strain ... Jun 13, 2021 at 18:30
  • My connection had been slow all morning, didn't suspect that was that cause for this but it was, thanks! Jun 23, 2021 at 19:08
  • Or no connection at all. Had this problem when buggy VM decided it didn't want to connect to the internet.
    – user115014
    Aug 9, 2021 at 14:21
  • 1
    I just had this issue. A connectivity issue is the only explanation (after following instructions in the other top post). On a 00M fibre that was showing 95+ up / 60+ down to a local server (in south Asia right now). But guessing the route to the registry node it was connecting was slow. Switched to 4G and worked.
    – Janaka
    Dec 8, 2022 at 12:32
11

I also faced the same issue. In my case git:// port was blocked and npm install took too long to time out. (longer than normal it waits before concluding that the process hung.)

A solution was to auto-rewrite all git:// URLs to https://:

Run the following command in your terminal


git config --global url."https://".insteadOf git://

npm install

Hope this helps!!

3
  • I believe this is my issue too, but not the port. I've been having routing issues with my internet provider. That's most likely the case
    – d.k
    Apr 1, 2021 at 16:42
  • I dont think npm has anything to do with git using this is not recommanded.
    – Ace
    Oct 20, 2022 at 8:30
  • This caused npm to simply hang for me for a solid 90 seconds instead, then proceed with the same problem as before.
    – Phoenix
    Sep 21 at 21:10
11

In my case, changing VPN worked.

1
  • In my case, disabling VPN worked.
    – codelover1
    Sep 26 at 6:56
10

Even after removing package-lock.json, npm i didn't worked for us. Instead, it got stuck on another message - still removeObsoleteDep removing fs-extra from the tree as its been replaced by a newer version.

Problem was, we used yarn occasionally. Installing using yarn will resolve the issue if it is the case.

1
  • 1
    For most people using NPM, adding yarn as well as NPM is a bad idea. It's worth choosing either yarn or NPM but installing both and using both in your project will come back to bite you when you use CI, and in development in general -some things yarn supports, but NPM doesn't, and vice-versa, and when you're running commands and they fail, it's a complete pain and makes you bleed development time. Least that's the very recent experience we had. Oct 5, 2020 at 18:38
10

I have tried all the solutions above without success. But I found this one : https://github.com/npm/cli/issues/4163#issuecomment-1010037450

alias npm="node --dns-result-order=ipv4first $(which npm)"

Then npm work correctly

8

I had this problem and the issue was that my VPN connection dropped and some of the packages were in my companies private package store.

5

This was my issue. I forget that I had previously setup an internal proxy for work to get Node modules. To check whether you are behind a proxy and see your proxy settings do:

npm config list

Mine output was:

https-proxy = "http://9.116.33.175/max*emphasized text*"

To clear it do:

npm config delete proxy
npm config delete http-proxy
npm config delete https-proxy
5

This might happen when changing from node v16 to v18 or later.

Changing IPv6 settings resolves this issue.

On MAC OS:

system settings -> network -> your connected network (usually Wi-Fi) -> details -> TCPI/IP -> Configure IPv6 -> "Link-Local only"

1
  • 1
    I tried everything for about an hour until I found this answer. How did you ever figure this out?
    – guero64
    Apr 30 at 16:29
3

You might not have package-lock.json so instead of this file you need to remove the npm-shrinkwrap.json file and try to execute npm install again.

About npm-shrinkwrap.json:

npm-shrinkwrap.json is a file created by npm-shrinkwrap. It is identical to package-lock.json , with one major caveat: Unlike package-lock.json , npm-shrinkwrap.json may be included when publishing a package.

3

In my case package-lock.json file didn't exists. I tried with my mobile hotspot and it worked. Might be some issue from wifi end. But my internet was working fine on wifi. Just issue was it got stuck on

loadIdealTree:loadAllDepsIntoIdealTree: sill install loadIdealTree

Moving on different network can also resolve your issue. I know it is very weird. Hope this will help too. To someone in future.

2
  • 1
    Moving on different network solved this issue Dec 12, 2022 at 10:18
  • Glad It worked for you Dec 12, 2022 at 13:28
3

For me the issue went away as soon as I disconnect from my company's VPN.

1
2

I experienced this, and had removed my package-lock.json and found out that a resource wasn't available on the network I was on.

2

I had same problem.

When I tried yarn, I got this message:

[1/4] Resolving packages... info There appears to be trouble with your network connection. Retrying...

One of the packages was not available actually!

2

In my case, I check the config about registry again.

npm get registry

And check this IP is working.


cuz' I find that I was setting something else like http://10.1.1.1

--- the self-registry like Verdaccio who's proxy here, but it's shutdown.

and I set again npm set registry https://registry.npmjs.org,

then it's work.

2

The only thing that helped me is commenting out the proxy & https-proxy lines at .npmrc file.

I don't even know how and when those two lines were set. Don't remember myself doing it.

2

NetBSD 9.3 solution - hardcode the registry.npmjs.org IP due to IPV6 problems.

edit: source - thanks khorben!

There's something weird going on with IPV6, what exactly I don't know, but a quick fix is to insert registry.npmjs.org into your /etc/hosts.

Get the IP:

ping registry.npmjs.org

Copy the IP (should be IPV4).

Open up /etc/hosts, with su powers, and insert the following line:

<PASTE THE IP HERE> registry.npmjs.org

So it turns into something like this on the last line:

104.16.26.35 registry.npmjs.org

Save the file.

Now npm should work.

1

I had faced this issue too. Cause : proxy was not set.

Use these commands to set your proxy: npm config set proxy http://username:password@host:port npm config set https-proxy http://username:password@host:port. proxy=http://username:password@host:port https-proxy=http://username:password@host:port https_proxy=http://username:password@host:port

Post this, npm install went through with no issues

1

I am able to solve it in 2 ways

  1. Delete 'package-lock.json'
  2. Remove proxy settings (http_proxy / https_proxy) from environment variables
1

This is my process:

  1. npm install --verbose => Understand better what got hung. Got stuck at loadAllDepsIntoIdealTree
  2. Removed package-lock.json from the same location as package.json => got stuck at FetchMetadata
  3. Do ssh-add, add in my key like this suggestion => SUCCESS
1

run:

npm cache clear --force
npm config set registry https://registry.npmmirror.com

Source : https://github.com/npm/cli/issues/4876#issuecomment-1174884230

1

In my case - I was using the wrong node version (not the lts one), so I just used the node version manager, and installed the latest lts version:

nvm install --lts

Hope it helps ✌️

1

Solution:

Try reverting to node version 16.2.0, then update your npm registry.

nvm install 16.2.0
npm config set registry https://registry.npmjs.org/

Try to install any node package e.g. npm install --global yarn


It is also helpful to clean your workspace by deleting your node_modules folder in the current directory, and remove package-lock.json file wherever package.json is located.

Other suggested some networking troubleshooting

System Preferences --> Network --> press Advanced --> TCP/IP tab --> on Configure IPv6 select Link-local only and apply

disabling IPv6 fixed this for me.

sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1 
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1

Background

I was really struggling with this. I saw that reverting to node v16.2.0 was a potential solution, but my nvm kept failing to download new node versions. I would see:

Downloading https://nodejs.org/dist/v16.2.0/node-v16.2.0.tar.xz...
################################################                                                                                                       32.2%
curl: (92) HTTP/2 stream 0 was not closed cleanly: INTERNAL_ERROR (err 2)

Binary download from https://nodejs.org/dist/v16.2.0/node-v16.2.0.tar.xz failed, trying source.
grep: /Users/<user>/.nvm/.cache/src/node-v16.2.0/node-v16.2.0.tar.xz: No such file or directory
Provided file to checksum does not exist.

I solved this problem by clearing the cache of nvm. Then I was able to revert from node v19.8.0 to v16.2.0 then reset my npm registry.

  • If you're not able to revert (nvm fails) try:
nvm cache clear
nvm install 16.2.0
npm config set registry https://registry.npmjs.org/
  • If you are getting SSL certificate errors, try using http:// protocol instead with:
npm config set registry http://registry.npmjs.org/
npm config set strict-ssl false

note: You can check your npm registry with npm config get registry

0

Had the same issue. For me it was caused by a webpack watcher. Stopping the watcher instantly advances the process.

0

if you still have trouble with this for windows users especially. U can start with re-install your npm in C:/yourfolder .

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Dec 9, 2021 at 12:09
0

I've tried removing the package-lock.json file but that did not work.

In the end updating node on my Mac to the latest version fixed the issue.

0

I use my own npm repo for some modules, and when it was down, the npm i just hangs.

0

In my case i had corrputed my npm config while trying a few other things.

i had added a cafile property

removed it using

npm config edit
0

So for my case it was a bugy latest version of node with npm.

I rocomande you to always check if you are on a LTS (Long Time Support) version since this ones are daily maintained and stable version.

I was using node without nvm so my first step was to remove it (purge it) it's a simple topic and you can get lot of solution on google depending on your OS.

Then I had to install mvn, you can also use it tutorial of install who uses Curl: in case you get a curl issue dont worry first open the curl install script on browser and copy past it on a folder in an install.sh file, dont forget to make it executable sudo chmod +x myInstall.sh then you can run it in your terminal

Once nvm installed you may get an issue where nvm is enable to find the remote repository, dont worry all you have to do is to add a file containing this line :

sudo nano ~/.curlrc    # use this or vim to create the source file 

-k   # put this as content and save

Now your nvm should be fine

To install a stable version use the following commande to search repos for LTS versions

nvm ls-remote | grep LTS 

Choose any version you want for my case for example

nvm install v16.13.0  

Now you will see that node got installed with a corresponding version of npm (I dont recommande updating npm in this case to avoid latest version issues )

Go ahaid and do your npm install xxxx@xxxx this should work just fine

Dont forget to read your project requirement and choose corresponding node and npm version.

nvm can switch current version of node and npm, go ahaid and read it documentation using nvm --help

Not the answer you're looking for? Browse other questions tagged or ask your own question.