82

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 npm@5.8.0
npm info using node@v8.9.2
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?

runnerpaul
  • 5,942
  • 8
  • 49
  • 118
  • 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. – Gajendra Singh Jan 16 '23 at 09:57

39 Answers39

100

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.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Mahmoud Felfel
  • 3,051
  • 3
  • 26
  • 19
31

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.

Hexworks
  • 514
  • 7
  • 17
23

This problem happens also when you have a very slow connection

Davide
  • 1,931
  • 2
  • 19
  • 39
  • 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 '20 at 00: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 ... – Carl von Blixen Jun 13 '21 at 18:30
  • My connection had been slow all morning, didn't suspect that was that cause for this but it was, thanks! – cschultz1272 Jun 23 '21 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 09 '21 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 08 '22 at 12:32
  • Yep. Switched to mobile hotspot and it worked. – user1160006 Apr 18 '23 at 19:17
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!!

Gautam Gahlawat
  • 362
  • 3
  • 8
  • 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 01 '21 at 16:42
  • I dont think `npm` has anything to do with `git` using this is not recommanded. – Ace Oct 20 '22 at 08:30
11

In my case, changing VPN worked.

A.Srisuma
  • 131
  • 1
  • 6
9

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.

Dani Vijay
  • 2,188
  • 2
  • 22
  • 37
  • 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. – user-12410035 Oct 05 '20 at 18:38
9

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

christophe
  • 311
  • 2
  • 4
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.

bikeman868
  • 2,236
  • 23
  • 30
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.

LeCodex
  • 1,636
  • 14
  • 20
Peter
  • 51
  • 4
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.

FaisalAhmed
  • 3,469
  • 7
  • 46
  • 76
3

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

bobt
  • 324
  • 3
  • 3
  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30918112) – Mahdi Zarei Jan 31 '22 at 09:44
3

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
Carlos Ferreira
  • 1,980
  • 2
  • 14
  • 18
3

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"

yN.
  • 1,847
  • 5
  • 30
  • 47
  • 1
    I tried everything for about an hour until I found this answer. How did you ever figure this out? – guero64 Apr 30 '23 at 16:29
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.

apalu
  • 31
  • 4
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!

Saxophonist
  • 677
  • 9
  • 16
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.

lejlun
  • 4,140
  • 2
  • 15
  • 31
Margarita
  • 21
  • 2
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.

NostraDavid
  • 195
  • 8
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

Kiranmayi
  • 31
  • 2
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
Andrei Surdu
  • 2,281
  • 3
  • 23
  • 32
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
harpreet singh
  • 405
  • 4
  • 4
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

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

Garrett
  • 319
  • 1
  • 13
0

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

Halcyon
  • 57,230
  • 10
  • 89
  • 128
0

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

MCS
  • 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](/help/how-to-answer). – Community Dec 09 '21 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.

paul.ago
  • 3,904
  • 1
  • 22
  • 15
0

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

Michał Wojas
  • 509
  • 1
  • 5
  • 16
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
Rishabh Dugar
  • 606
  • 5
  • 16
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

0

Just execute the following code in your node js cmd:

  1. git config --global http.sslVerify false

  2. npm install

This worked for me.

  • 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](/help/how-to-answer). – Community Mar 03 '22 at 10:27
0

Faced a similar issue and in my case, I did upgrade the node version which fixed the issue also sometimes we need to try with or without a VPN. Please downgrade the node version if require and if that is compatible with your packages.

Subramanian
  • 170
  • 3
  • 12
0

For me (MacOs 12.5 m1 machine) it was the ssh-agent issue. This comment fixed the issue for me. Run ssh-add and enter passphrase if any to add the current ssh-key to the ssh-agent. You can verify this using ssh-add -l

You can add the ssh-agent permanently to the keychain. To the .ssh/config file, add the following lines:

 Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_rsa
Noushad
  • 6,063
  • 3
  • 25
  • 28
0

Can't give up more :(

mine was

idealTree:npm: sill idealTree buildDeps

Download yarn here manually. If u r on windows download the .msi one, so ez

Gray Hat
  • 39
  • 3
0

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 ✌️

2beens
  • 743
  • 1
  • 6
  • 8
0

npm install was hanging for me when Windows ransomware protection was blocking folder access to node.exe.

This can be checked in Windows Security:

Virus & threat protection > Ransomware protection > Allow an app through controlled folder access > Add an allowed app > Recently blocked apps

embee
  • 1,007
  • 7
  • 15
0

Yet another solution!

I realized ip6tables was dropping ICMPv6 packets on npm ping. I allowed ICMPv6 packets through and it solved it.

Well, not exactly...

  • I saw dropped ICMPv6 packets.
  • I went ip6tables -P INPUT ACCEPT. npm ping and npm i worked.
  • I restored ip6tables -P INPUT DROP and added an ICMPv6 ACCEPT rule. npm still worked.
  • I removed the ICMPv6 rule, just to be sure. npm still worked, although it didn't work earlier with the same conditions.

So I can't exactly explain what happened. Check if your firewall drops any packets on an npm command, and take it from there.

gilad905
  • 2,842
  • 2
  • 16
  • 23
  • This partially worked for me, everime I boot the system I've to do: `npm cache clear --force && npm config set registry https://registry.npmmirror.com && sudo ip6tables -P INPUT ACCEPT` – Luca Reccia Jan 05 '23 at 17:15
0

If you have package-lock.json file in your folder. Try to delete it and then run npm install command again. This should helps!

Kai-Chun Lin
  • 185
  • 1
  • 2
  • 10
  • 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](/help/how-to-answer). – Community Mar 21 '23 at 02:17
0

I got stuck there when i was setting up a private registry/Proxy with Verdaccio. So for devs in the future that made the same error as me:

Make sure you set the uplink in your Verdaccio-Config correctly:

uplinks:
  npmjs:
    url: https://registry.npmjs.org/

And when you change your npm configs, make sure you set the protocol aswell! dont do npm set registry localhost:4873, do npm set registry http://localhost:4873.

And for good measurement (i followed the steps provided here first so i dont know if this actually helps), just clean the cache, delete the lockfile etc (follow Top answer).

Raqha
  • 754
  • 4
  • 17
-2

sometimes your internet speed is slow that's why it take sometime to download the required files. just wi

IMRAN H
  • 11
  • 4
  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 10 '22 at 05:46