npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.46k stars 3.15k forks source link

[BUG] npm install will randomly hang forever and cannot be closed when this occurs #4028

Open Metritutus opened 2 years ago

Metritutus commented 2 years ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

When running npm install it will sometimes hang at a random point. When it does this, it is stuck forever. CTRL+C will do nothing the first time that combination is pressed when this has occurred. Pressing that key combination the second time will make the current line (the one showing the little progress bar) disappear but that's it. No further responses to that key combination are observed.

The CMD (or Powershell) window cannot be closed regardless. The process cannot be killed by Task Manager either (Access Denied, although I'm an Administrator user so I'd assume the real reason is something non-permissions related). The only way I have found to close it is to reboot the machine.

My suspicion is it's some sort of deadlock, but this is a guess and I have no idea how to further investigate this. I've tried using Process Explorer to check for handles to files in the project directory from other processes but there are none. There are handles held by the Node process npm is using, and one for the CMD window hosting it, but that's it.

Even running with log-level silly yields no useful information. When it freezes there are no warnings or errors, it just sits on the line it was on. This is some log output from one of the times when it got stuck (I should again emphasise that the point where it gets stuck seems to be random, so the last line shown here isn't always the one it freezes on):

npm timing auditReport:init Completed in 49242ms
npm timing reify:audit Completed in 55729ms
npm timing reifyNode:node_modules/selenium-webdriver Completed in 54728ms
npm timing reifyNode:node_modules/regenerate-unicode-properties Completed in 55637ms
npm timing reifyNode:node_modules/ajv-formats/node_modules/ajv Completed in 56497ms
npm timing reifyNode:node_modules/@angular-devkit/schematics/node_modules/ajv Completed in 56472ms
[##################] \ reify:ajv: timing reifyNode:node_modules/@angular-devkit/schematics/node_modules/ajv Completed in 564

The only thing that I can think of right now is that Bit Defender (the only other application running) is interfering somehow, however it's the one application I can't turn off.

I've seen this issue occur on different projects, on different network and internet connections, and on different machines. Does anyone have any advice on how to investigate this, or at the very least a way to kill the process when it hangs like this without having to reboot the machine? Being forced to reboot when this issue occurs is perhaps the most frustrating thing in all of this.

Expected Behavior

npm install should either succeed or show an error. If it gets stuck it should either time-out or be closable by the user.

Steps To Reproduce

  1. Clear down the node_modules folder (ie with something like rmdir /q /s)
  2. Run. npm install
  3. Watch and wait.
  4. If it succeeds, repeat the above steps until the freeze is observed.

Environment

prefix = "C:\Users\\AppData\Roaming\npm"

; "user" config from C:\Users\.npmrc

//pkgs.dev.azure.com//_packaging//npm/registry/:_authToken = (protected)

; node bin location = C:\Program Files\nodejs\node.exe ; cwd = C:\Users\ ; HOME = C:\Users\ ; Run npm config ls -l to show all defaults.

stil commented 2 years ago

In my case antivirus/EDR software enabled has 100% correlation with this freeze.

CXCubeHD commented 2 years ago

In my case antivirus/EDR software enabled has 100% correlation with this freeze.

I am on Linux so no Antivirus.

Alzy commented 2 years ago

@CXCubeHD What I finally did to get past this mess (and I don't really consider it a good solution, just something to get it working and move on while a proper solution is hopefully implemented) was to just clone the repo as a submodule in a folder in the root called packages. Then, install it with npm using npm install /packages/module. Essentially, installing the package locally. You have to take care to do a recursive git clone as part of your build step when shipping to production though so it's a tad tedious but it did the job for me.

stil commented 2 years ago

In my case antivirus/EDR software enabled has 100% correlation with this freeze.

Also to add on my previous comment, the issue did not happen when npm cache was empty on the computer.

So the first npm install on a new computer succeeded, and second (and subsequent) run freezed.

Can anyone else confirm whether the issue exists when there are no packages in the cache? (Or anything else that npm persists between runs in user directory)

zakofpl commented 2 years ago

I'm having same issue trying remotely "npm ci" my short list of dependencies, even if my npm cache is cleared. Same deps are being installed successfully on my local Win machine, but never on remote Ubuntu.

And it drops any attempt to reconnect via SSH.

michaelbutler commented 2 years ago

I'm having this issue and I decided to leave it running "forever" to see if it actually would do something. It finally exited with this error message:

(##################) ⠹ reify:es-abstract: timing reifyNode:node_modules/es-abstract Completed in 1989ms
npm timing reify:rollback:createSparse Completed in 297ms
npm timing reify:rollback:retireShallow Completed in 0ms
npm timing command:install Completed in 444574ms
npm verb type system
npm verb stack FetchError: request to https://registry.npm.vzbuilders.com:4443/npm-registry/api/npm/npm-registry/zip-stream/-/zip-stream-4.0.4.tgz failed, reason: connect ETIMEDOUT 66.218.85.57:4443
npm verb stack     at ClientRequest.<anonymous> (/home/USERNAME/.volta/tools/image/npm/8.13.2/node_modules/minipass-fetch/lib/index.js:130:14)
npm verb stack     at ClientRequest.emit (node:events:527:28)
npm verb stack     at TLSSocket.socketErrorListener (node:_http_client:454:9)
npm verb stack     at TLSSocket.emit (node:events:539:35)
npm verb stack     at emitErrorNT (node:internal/streams/destroy:157:8)
npm verb stack     at emitErrorCloseNT (node:internal/streams/destroy:122:3)
npm verb stack     at processTicksAndRejections (node:internal/process/task_queues:83:21)
npm verb cwd /home/USERNAME/src/pure
npm verb Linux 5.18.5-1-MANJARO
npm verb node v16.15.0
npm verb npm  v8.13.2
npm ERR! code ETIMEDOUT
npm ERR! syscall connect
npm ERR! errno ETIMEDOUT
npm ERR! network request to https://registry.npm.vzbuilders.com:4443/npm-registry/api/npm/npm-registry/zip-stream/-/zip-stream-4.0.4.tgz failed, reason: connect ETIMEDOUT 66.218.85.57:4443
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
... (snipped)

Indeed when I try to simply run:

wget https://registry.npm.vzbuilders.com:4443/npm-registry/api/npm/npm-registry/zip-stream/-/zip-stream-4.0.4.tgz

at least at this current moment, I get a network timeout. I am on typical home internet, no proxy.

ljharb commented 2 years ago

What registry is that? What does npm config get registry print out?

michaelbutler commented 2 years ago

What registry is that? What does npm config get registry print out?

It outputs https://registry.npmjs.org/

BUT... thank you, your comment led me to believe it was related to the project I was in. It's this fairly old one from Yahoo/Verizon. https://github.com/pure-css/pure and it looks like they commit their package-lock.json file, and in that file has links to vzbuilders. I deleted package-lock.json, re-ran npm install and it worked. So, looks like not related to this issue (unless this issue is ALSO a network problem with a specific package).

Dezzpil commented 2 years ago

I had similar issue: npm ci always stacks on when i run it terminal in my Jetbrains IDE image

When i close IDE and run script from system terminal - npm ci complete successfully

Maybe IDE starts indexing node_modules folder too early and interferes with install process.

JimmyHoyosDev commented 2 years ago

I am actually having the same issue on Mac. As soon as we jumped from LTS node 10 to LTS 16. Boom issues started. But I have been able to pinpoint the hang to private dependencies hosted on bitbucket using git+ssh protocol. As soon as I remove those dependencies it all installs fast and normal. So based on that we moved those repos and dependencies on github and started using the npm registry they offer and from an installation that took 5 - 10 min it went to 3 - 5 sec lol. I tested using git+ssh with node LTS 14 and it installed fast and normal. Not sure what changed on node 16. But keep in mind that my dependencies do install with node 16 it just makes my Mac fans go into full speed and it takes longer to install. Another test I did was using my personal Macbook and still the same issue. Would really like to understand why this is happening with node >= 16

ljharb commented 2 years ago

@colomjimmy28 generally it's best to never bump more than 1 LTS release at a time - ie, go from 10 to 12 to 14 to 16. That would help figure out if it's node, or npm, that makes a difference.

JimmyHoyosDev commented 2 years ago

@ljharb I agree at some level but the project in hand is not something complex or big. Reason why we jumped to 16. Once again I am blaming ssh. Something there that is just not playing nice.

evjero commented 2 years ago

Still seeing the reify hang on fresh npm install. There appears to be a lot of CPU usage at this stage. Waiting for completion takes ~15 minutes, but I've seen it take up to 45 minutes in the past, depending on system load.

Environment:

mmiretsky commented 2 years ago

Doesn't seem like the npm team is planning to fix this issue, which is unfortunate. I am quite disappointed with the way this software is being maintained. Our team is going to continue using npm v6 for the foreseeable future.

pvrobays commented 2 years ago

Not sure if I had the same issue but while running npm ci on my windows gitlab runner for an older project, it kept being stuck on: reifyNode:node_modules/watchpack-chokidar2 If we kept waiting, It could take more than an hour to finish the reify. When running the ci on the same machine within cmd or powershell it succeeded (reify took ~10s)

For me the solution was to verify the npm cache before running npm ci: npm cache verify && npm ci Or, you could also use a temporary npm cache: npm ci --cache /tmp/empty-cache

I hope this helps for some devs!

addlistener commented 2 years ago
image image

same here when trying to npm install --verbose in https://github.com/electron-react-boilerplate/electron-react-boilerplate

npm 8.11.0

node 16.16.0

yarn works for me eventually.

ddzialak commented 2 years ago

my observation for a case when it consumes 100% CPU for a long time and finally it's done:

liuzhaomax commented 2 years ago

I'm having a similar issue after upgrading to node 16.13.1 and npm 8.3.0 (running on centos 7) As others have mentioned, "npm install" gets progressively slower on the fetches to a point where it completely hangs.

After I downgraded npm back to version 6.14.15 ( npm install -g npm@6 ), the "npm install" completes quickly and successfully.

works for me!!!

lclarkg18 commented 2 years ago

Same issue here, MacOS stuck on reify:typescript: timing reifyNode:node_modules/@mui/material when running npm ci...

Downgrading to npm version 6 sucks because it constantly changes the version of the lock file within our team..

devniel commented 2 years ago

Lenovo Thinkpad user here; after a successfully npm install with node v16.14.0 and npm v8, the computer is unusable, slow, opening ctrl+alt+supr or Task Manager takes minutes. The strange thing is, based on reporters, that cpu, memory, SSD and temperature is okay, it's really strange.

Tried with node v14 and npm v6 and no problem.

tFaster commented 2 years ago

Same issue here in our whole lab! Reproducable on all Windows 10/11 computers with latest npm v8. After npm ci or npm install everything freezes and computers are completely unusable. You can hardly 'restart' the system. Needs hard power off/on. Donwgrading to npm v6 solves the issue which certainly is not a long term solution

planetsLightningArrester commented 2 years ago

Adding my 2 cents herer. Facing it in Ubuntu 22.04 on an EC2 AWS instance ONLY when running 2 GitHub Runners: one gets stuck on npm ci. Node: 18.9.0 npm: 8.19.1

Happens even when one of the runners is idle. Having only one runner works.

mirek commented 2 years ago

Started happening for me after I pnpm linked one of local deps - it started affecting npm globally in all places. After npm publish it hangs.

josh2112 commented 2 years ago

If you're on Windows 11, see if you get a "controlled folder access" notification right about the time npm freezes.

Controlled Folder Access is a feature of Windows that blocks some processes from writing to your AppData folder. You should be able to click on the notification, see that npm is trying write there, and unblock it. Or, if your Protection History window shows nothing, like mine, you can disable controlled folder access (at least temporarily). Just search for it in the Start menu. It'll open up Windows Security to the Ransomware Proection page where you can flip a switch to turn it off.

Then kill and retry your npm install.

mirek commented 2 years ago

If you're on Windows 11...

my issue was on macOS fyi.

ilan-belfer commented 2 years ago

I'm having a similar issue after upgrading to node 16.13.1 and npm 8.3.0 (running on centos 7) As others have mentioned, "npm install" gets progressively slower on the fetches to a point where it completely hangs.

After I downgraded npm back to version 6.14.15 ( npm install -g npm@6 ), the "npm install" completes quickly and successfully.

npm install -g npm@6 Worked for me too.

kacluk123 commented 1 year ago

I constantly have a problem with npm v8 on windows 10. Randomly stucking on npm install (cache miss). This is a nightmare. Cache clear is not helping.

sierraleonez commented 1 year ago

I have a similar one, it takes a looong time at some random package and it doesn't resolve for hours, sometimes I leave it and go to bed then the installation is finished in the morning. It happens in all my company's old projects.

I've tried:

mmiretsky commented 1 year ago

It seems like the problem may be fixed in npm v9. I upgraded to v9.1.1 and haven't experienced this problem yet.

cscleison commented 1 year ago

i tried with npm 9 and the problem persists for me. only works with 6 still

filipe-costa commented 1 year ago

I was currently having this exact issue when installing prettier on WSL2.

I resolved the issue by doing the following:

  1. rm -rf node_modules
  2. rm package-lock.json
  3. npm cache clean -f
  4. npm cache verify -> make sure it is empty
  5. npm install

I hope these steps might help someone else.

acanimal commented 1 year ago

Same here. node 18.12.1 npm 8.19.2

the only solution was to downgrade to npm v6 npm install -g npm@6 😭

mmiretsky commented 1 year ago

@acanimal - could you try it with npm v9?

StillStarving commented 1 year ago

@acanimal - could you try it with npm v9?

Not sure if this will help anyone but I discovered it hangs for me because the default DHCP settings were causing it to use IPv6 addresses that weren't responding. The solution that worked for me was to disable DHCP, use an static IP address and force ubuntu to use IPv4. I did this by Edit the netplan config.yaml

cd /etc/netplan config.yaml

add the following to the config.yaml (I'm new here and don't know how to indent properly so you'll need to fix that in your file):

network: ethernets: enp0s3: link-local: [ ipv4 ] dhcp4: no addresses: [<your ipv4 address>/24] gateway4: <your gateway IP> nameservers: addresses: [8.8.8.8, 8.8.0.0] version: 2

Restart the machine.

After rebooting npm worked perfectly.

haydenyoung commented 1 year ago

Running node v16.17.1 and npm 9.2.0 and seeing the same problem although not with the freeze up of npm. Ctrl+C is still responsive but npm will not advance from a certain point. I can leave it for hours and it will not complete.

On one repo I'm seeing it hang at the following (from the npm logs):

11818 warn deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
11819 timing reifyNode:node_modules/core-js Completed in 7948ms
11820 timing reifyNode:node_modules/rxjs Completed in 8351ms

The last line would indicate that it has completed successfully but there is nothing after that describes what npm is now up to. It just seems to have completed and doesn't want to do anything else but won't complete either.

There seems to be no way to debug this issue and it is a showstopper; I can no longer work on the module because I can't install its dependencies.

mmiretsky commented 1 year ago

@haydenyoung - does the same repo work with NPM v6?

naviln commented 1 year ago

Sharing my experience, in case it helps anyone out there.

I was having similar symptoms to this issue on my build for a long time.

During npm install, it would get up to rxjs, and then just hang there for a veeery long time. Ctrl+C twice, then Y and enter would stop it. When I go to run npm install again, it completes straight away.

After clearing node_modules/npm cache folders and repeating the process a few times, I finally walked away for 20 minutes, came back and it actually it did complete (but very slowly!)

I decided to dig into the npm cache logs which are located here:

to see if there were any clues, and hey presto! I found this line:

2979 timing reifyNode:node_modules/material-design-icons Completed in 617451ms

material-design-icons was taking over 10 minutes to download! This was mistakenly added to my repo a long time back, and it is actually not being used. I just removed it, and now my npm install is back to a manageable timeframe.

TLDR - delete node_modules folder, delete npm cache folder, run npm install again, check the npm cache log, and look closely for any package that has a long download time (> 600000 milliseconds) to help identify the problem package, so at least you can try to address/remove it, (if possible).

Good luck!

Konglomneshued commented 1 year ago

Same issue on Node 18.13.0 LTS with 8.19.3 npm

universallythinking commented 1 year ago

npm config set strict-ssl false

worked for me

Oriery commented 1 year ago

For me adding additional memory to a system helped.

I was running npm install on a linux vm with only 1GB RAM. Adding swap file with size 4GB totally helped.

I hope this helps someone)

raphael22 commented 1 year ago

For us, it was the access path length. (node 16/18, npm 6/8, Fedora/WSL2)

A long path would always result in a reify hanging forever.

Renaming or moving repo to a shorter location did the trick.

septatrix commented 1 year ago

For me it gets stuck during an epoll_wait syscall right after arborist:ctor Completed in 1ms

strace shows:

epoll_wait(13, [], 1024, 49)            = 0
epoll_wait(13, [], 1024, 0)             = 0
epoll_wait(13, [], 1024, 50)            = 0
...(repeating)

pstack shows:

Thread 1 (Thread 0x7f17c43acc00 (LWP 6961) "npm create vuet"):
#0  0x00007f17c0f2f196 in epoll_wait () from /lib64/libc.so.6
#1  0x00007f17c44b9afe in uv.io_poll.part () from /lib64/libuv.so.1
#2  0x00007f17c44a372a in uv_run () from /lib64/libuv.so.1
#3  0x00007f17c195161d in node::SpinEventLoop(node::Environment*) () from /lib64/libnode.so.108
#4  0x00007f17c1a4e78b in node::NodeMainInstance::Run(int*, node::Environment*) () from /lib64/libnode.so.108
#5  0x00007f17c1a53bd8 in node::NodeMainInstance::Run() () from /lib64/libnode.so.108
#6  0x00007f17c19da0b8 in node::LoadSnapshotDataAndRun(node::SnapshotData const**, node::InitializationResult const*) () from /lib64/libnode.so.108
#7  0x00007f17c19da52c in node::Start(int, char**) () from /lib64/libnode.so.108
#8  0x00007f17c0e4a510 in __libc_start_call_main () from /lib64/libc.so.6
#9  0x00007f17c0e4a5c9 in __libc_start_main_impl () from /lib64/libc.so.6
#10 0x0000561dbe636035 in _start ()
monkbroc commented 1 year ago

I enjoy receiving updates about this issue. It's like hearing from an old friend who writes from time to time and doesn't get bothered even if you don't reply. You know they will write again a month or two from now with new stories.

PhilETaylor commented 1 year ago

ok I'll chime in...

Dual stack ip4 and IPv6 on latest MacOS Mac Studio with 128Mb RAM on 1Gbps fibre connection to the desk. both ip4 and ipv6 are valid and work perfectly all the time during the day with anything non-npm like

Dual stack ip4 and IPv6. = npm hangs 100% of the time.

Disable IPv6 and use ip4 only = npm works 100% of the time.

As soon as I disable ipv6 I can 100% of the time get npm upgrade to complete.

As soon as I enable ipv6 (dual stack with ip4 as is the norm) then 100% of the time npm upgrade stalls/hangs...

Enough7 commented 1 year ago

On Ubuntu 20.04 disabling IPv6 fixed the problem for me. My Settings Ubuntu Connection Settings image It looks like you need to reconnect the modified connection so the settings take effect.

pwagsc commented 1 year ago

Had this same issue with hang on reiify. Fails 95% of the time. Occasionally works. On Ubuntu, with versions 6.?, 8.5, 9.3, and now 9.5. The workaround that has worked 100% (so far) of the time is to:

This has worked 100% of the time for me. I have few problems with same on Windows although I have seen some stalls but a timeout seems to get it going again in few seconds. Most of the time it just works on Windows. It should be noted that the Ubuntu is a single thread processor where as the Windows is a 16 thread processor with single thread performance twice that of the Ubuntu box- maybe makes a difference. Hope this helps.

PhilETaylor commented 1 year ago
rm -Rf node_modules
rm package-lock.json
npm install --package-lock-only

Now its hanging

(⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠇ idealTree:[redacted-current-folder]: sill idealTree buildDeps

still hanging... still hanging... still hanging... still hanging...

give up...

ctrl+c disable ipv6...

npm install --package-lock-only
up to date, audited 667 packages in 44s
72 packages are looking for funding
npm install --no-optional
added 665 packages, and audited 666 packages in 5s
pwagsc commented 1 year ago

I should have noted that I have ipv6 disabled on Ubuntu but it still fails with the vanilla install (ie npm install --no-optional) without the prebuild lock.

I should also have commented that npm cache clear -f after clearing lock and node_modules also works almost every time without prebuilding lock (just the npm install). I have only seen one failure in many tries.

Also my build server is lightly loaded..

Just data points...

Interestingly IPv6 is enabled on Windows but I have never had a complete hang, just a few brief stalls.

anandncode commented 1 year ago

Using npm@9.3.1

For me it was the registry. npm was unable to reach registry. Instead of giving an error, it just hung for 20, 30 minutes with out any information as such

This didn't happen with the previous npm

ZainlessBrombie commented 1 year ago

Quick sidenote: For a more detailed log, use --loglevel silly