Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
Metritutus opened this issue Nov 10, 2021 · 218 comments
Closed
2 tasks done
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@Metritutus
Copy link

Metritutus commented Nov 10, 2021

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

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

  • npm: 8.1.3
  • Node: v16.13.0
  • OS: Windows 10 Version 21H1 (OS Build 19043.1288)
  • platform: Lenovo ThinkPad
  • npm config:
; "builtin" config from C:\Users\<REDACTED>\AppData\Roaming\npm\node_modules\npm\npmrc

prefix = "C:\\Users\\<REDACTED>\\AppData\\Roaming\\npm"

; "user" config from C:\Users\<REDACTED>\.npmrc

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

; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\Users\<REDACTED>
; HOME = C:\Users\<REDACTED>
; Run `npm config ls -l` to show all defaults.
@Metritutus Metritutus added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Nov 10, 2021
@Bizzle-Dapp
Copy link

If there was ever a linked example on "How to report an issue", this would probably be it.

@LegendaryMediaTV
Copy link

I was getting this error last night. It seemed as though all NPM operations were going slow and/or hanging. I tried reinstalling Node/NPM/etc. Not sure if it's related, but last night I also noticed that the NPM site was taking a while to pull up.

It finally seemed to clear itself up about an hour ago and everything has been working for me since. I'm guessing it was something server-side, though NPM's status page doesn't show anything as of yet.

@Metritutus
Copy link
Author

I was getting this error last night. It seemed as though all NPM operations were going slow and/or hanging. I tried reinstalling Node/NPM/etc. Not sure if it's related, but last night I also noticed that the NPM site was taking a while to pull up.

It finally seemed to clear itself up about an hour ago and everything has been working for me since. I'm guessing it was something server-side, though NPM's status page doesn't show anything as of yet.

I'm not sure if that's the same thing. If it were network connection related, I'd assume it would time out at some point. I'd certainly expect to be able to cancel out of the process.

@LegendaryMediaTV
Copy link

I'm not sure if that's the same thing. If it were network connection related, I'd assume it would time out at some point. I'd certainly expect to be able to cancel out of the process.

I would have expected a network connection timeout too, but I waited well over an hour (for things that normally take a minute or less) and the process just sat frozen with a partial progress bar. I was, however, able to cancel out of the process on Windows Terminal, which seems to be the only difference.

I even tried a different machine with a different version of Node/NPM (on a different network in a different city) during that time and it had similar issues (i.e., taking a couple minutes to run npm outdated which normally takes a few seconds), but I didn't actually try an install.

@danmana
Copy link

danmana commented Nov 22, 2021

I've been having the same problem once in a while: npm install is stuck and I can't cancel the process.

For the last few months, this happened rarely, and when it happened I had to restart my laptop to get it working again.

Last week I updated Node from 14 to 16, and npm from 6 to 8. Everything seemed fine until today...

However, today I can't get npm install to finish, not even once.
I've tried restarting my laptop about a dozen times, but it doesn't help.
I've tried npm cache clear --force and deleting node_modules - nothing helps.

I tried npm install --verbose, but I don't get any more info than this:

npm http fetch GET 200 https://registry.npmjs.org/@types/lodash/-/lodash-4.14.168.tgz 38952ms (cache miss)
npm timing reifyNode:node_modules/@sealsystems/mongo/node_modules/@types/lodash Completed in 45927ms
npm timing reifyNode:node_modules/@sealsystems/assert-mongo-error/node_modules/@types/lodash Completed in 45946ms

Note: it's not always the same dependency that it gets stuck at.

What I've found that seems strange is that as it fetches dependencies it starts getting progressively slower, until it gets stuck (when the timing gets about 30-45 seconds).
Here are some lines from the logs (the lines are in order, but I skipped a lot of them in between)

npm http fetch GET 200 https://registry.npmjs.org/figures 216ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz 6802ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz 9951ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/decamelize-keys/-/decamelize-keys-1.1.0.tgz 11129ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz 18008ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@types/stringify-object/-/stringify-object-3.3.0.tgz 26988ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@types/lodash/-/lodash-4.14.168.tgz 38952ms (cache miss)

Maybe relevant - I have a few private scoped packages configured in npmrc

@myprivatescope:registry = "https://npm.pkg.github.com/"
//npm.pkg.github.com/:_authToken=ghp_***

though it doesn't seem to get stuck on them

npm http fetch GET 200 https://npm.pkg.github.com/@myprivatescope%2fconsul 515ms (cache miss)

I've tried setting npm config set registry http://registry.npmjs.org/, it seems to move a bit faster in the beginning, but still ends up stuck.

It seems today is not a good day for developing 😢

Windows 10 21H1 build 19043.1348
Node: v16.13.0
NPM: tried with 8.1.3, 8.1.4, 7.19.1 none work
Bitdefender Endpoint Security tools 7.2.2.101 (not sure if this is the issue)

Edit: tried uninstalling node completely, cleaning everything up and reinstalling, but it didn't work ... still stuck

@danmana
Copy link

danmana commented Nov 22, 2021

After trying all day to reinstall and make npm work I ended up:

  1. installing Ubuntu WSL
  2. installing node in ubuntu
  3. Copying my settings to ~/.npmrc

This actually worked, although slowly, it never got stuck npm timing reify Completed in 315565ms

I have no idea why even after purging every reference to node or npm from my laptop and doing a fresh install, it still didn't work on Windows.

@CFT-Chris
Copy link

I've been running into this as well. Happens on reifyNode in the npm output.

npm is latest version (8.3)
platform is ubuntu 21.10

I did just recently update from npm 6.x to latest. One thing I note is the warning message saying package-lock.json is out of date and needs to be rewritten (one-time operation).

For smaller projects, it squeaks by but only after many periods of CPU lock ups and spending more time than it used to with npm version 6.x.

For bigger projects, the only new observation I can add is that the number of node processes running simultaneously explodes, and they are all hogging the CPU and memory. So now memory swap processes enter the mix and the whole computer grinds to a halt.

Eventually I have to killall node if the computer isn't completely locked up, otherwise I have to do a hard reset. I still haven't succeeded to complete the "npm install" on larger projects.

@bernwong
Copy link

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.

@CFT-Chris
Copy link

With 8.3.0, I got by installing all the dependencies of my larger projects by running npm install in small subsets of said dependencies, until all were installed.

It appears if you try to install multiple large dependencies at once, there is a greater probability of parallel npm install processes of the subdependencies causing an out-of-memory condition on the computer, which I eventually had to kill in order to gain control of the computer again.

@tekumara
Copy link

In my case it was network related. I had a private registry in npm config and I wasn't on the VPN to access it.

@darkartswizard
Copy link

darkartswizard commented Jan 13, 2022

Seeing this as well on a Mac.
Might be network dropouts.
EDIT: Downgraded to 6.14.15
Restarted machine, cleared cache, removed all packages, deleted node_modules, deleted package-lock.
Then we started putting Dependancies and devDependancies packages back a few at a time.
Eventually got it to build without error.

@begroff
Copy link

begroff commented Jan 15, 2022

I am getting this error as well on a windows PC using the command prompt (cmd.exe). I've tried the following combinations and was able to reproduce the stuckness each time (I was using nvm for windows to switch versions):

node v16.13.1 / npm 8.1.2
node v17.2.0 / npm 8.1.4
node 16.10.0 / npm 7.24.0

I do have AV Defender installed, which I can't disable due to it being a company installed anti-virus software. I was also running Fiddler4 and haven't seen any HTTP errors related.

I then switched to a git bash terminal and was able to run npm install 3 times with version 16.13.1/8.1.2 and no hangs. I also ran npm ci 3 times with no hangs.

My git version installed on windows was 2.17.1.windows.2.

@darkartswizard
Copy link

I'm documenting my adventures in npm. Never occurred to me to switch from ZSH to Bash or use Git Bash. Good post!

@begroff
Copy link

begroff commented Jan 15, 2022

Thanks. I was also able to reproduce the stuckness using PowerShell too. Now if I could figure out how to get my azure pipeline to run git bash I'll be golden. I'm going to try to use the bash task https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/bash?view=azure-devops

@begroff
Copy link

begroff commented Jan 16, 2022

In case anyone is having this issue when running azure pipelines with a self-hosted agent. Below is a solution that worked for me. The only requirement for the server/computer that is running the pipeline is to have git for windows installed so you can access the sh.exe

  - task: CmdLine@2
    displayName: Restore NPM Packages
    inputs:
      script: '"C:\Program Files\Git\bin\sh.exe" --login -c "npm ci"'
      workingDirectory: '' # Directory location where the package.json file is 
      failOnStderr: false
    timeoutInMinutes: 15

@stacy-rendall
Copy link

I have also been seeing this issue since NPM 8 (initially on Node.js 14 and more recently on Node.js 16), Windows 10

It is kind of intermittent, seems to happen more frequently on Bash (from Git for Windows) than PowerShell or CMD

The only workaround I have been able to identify is a complete restart of the system, manually delete node_modules and package-lock.json then run npm i

@CFT-Chris
Copy link

I've found the reason and a workaround for my particular scenario. In my case, I had a dependency on a package from a git repo, which also had a git repo dependency, and it set off an npm install fork bomb, causing out of memory conditions on my machine.

I've logged the specific bug, proposed solution and workaround here: npm/pacote#127 (comment)

@jumpmouse
Copy link

I have this problem for a while now. I thought it that was some problem with my project's node_modules or npm version mismatch problem.

Just now, I tried to install one package globally, and encountered exact same problem.
nodejs 14.18.1
npm 8.1.4

not sure if this helps: with -verbose enabled, this is what I've noticed:

  • npm freezes randomly
  • no relation with cache hit status
  • everything noted before, plus
  • if I wait forever, it takes exactly 143 seconds (!) to move onto next line (don't have screenshot, trust on my word :) ). After 5-10 lines, it continues with normal speed and eventually finishes.

And this is only one package (bigger one, with dependencies).
I've tried with next random one, same thing.

@ljharb
Copy link
Contributor

ljharb commented Mar 8, 2022

@jumpmouse npm 8.1.4 is very old; can you try with v8.5.3?

@jumpmouse
Copy link

@ljharb thanks, I've updated to 8.5.3

Unfortunately, same behavior.
This time I've tried npm i on my medium size Angular project (removed node_modules and cleared cache).

It runs fast, then slows down and freezes.
if I terminate (Ctrl+C) process on freeze and start again, it freezes on same spot.
if I wait forever, it freezes on same line and then on couple more. Each freeze lasts for 2-3 minutes.
Eventually, instalation finishes (after about 7-8 minutes).

@darkartswizard
Copy link

I've had no issue since posting. I was able to narrow down one issue an old wdio and current webdriverio package installed. I removed the sync (fibers) package as well. Then I used ncu to find conflicting package versions. Then ncu -u to update the package. Followed by npm i to create the package-lock. Aside from an occasional unexplained issue with a port-in-use package, my Mac has been relatively stable ever since. Hope this helps.

@rayeaster
Copy link

rayeaster commented Mar 23, 2022

I am getting this error as well on a windows PC using the command prompt (cmd.exe). I've tried the following combinations and was able to reproduce the stuckness each time (I was using nvm for windows to switch versions):

node v16.13.1 / npm 8.1.2 node v17.2.0 / npm 8.1.4 node 16.10.0 / npm 7.24.0

I do have AV Defender installed, which I can't disable due to it being a company installed anti-virus software. I was also running Fiddler4 and haven't seen any HTTP errors related.

I then switched to a git bash terminal and was able to run npm install 3 times with version 16.13.1/8.1.2 and no hangs. I also ran npm ci 3 times with no hangs.

My git version installed on windows was 2.17.1.windows.2.

similar issue on windows10 and took nearly more than one hour to complete

$ node --version
v16.13.2

$ npm --version
8.1.2

...npm timing npm Completed in 4213666ms...

@robertwbradford
Copy link

robertwbradford commented Apr 5, 2022

We have multiple developers in our org (mostly on Macs) also seeing issues like this after going to Node 16. npm ci seems to be especially problematic, but we have noticed it in other commands as well. For example, in one project (a lerna monorepo) we have a "setup" script that runs npm ci and then some various lerna execs. It has got to the point where no one can run it anymore. It just freezes the whole machine and we have to do a hard restart. If you view the "Activity Monitor" while its going, there doesn't seem to be any indication of a problem. The machine just stop responding. Not sure how to even debug this.

@adipascu
Copy link

adipascu commented Apr 5, 2022

I think this is a duplicate of #3078, the fix for this was released in npm v8.6.0

@batressc
Copy link

batressc commented Apr 6, 2022

In my experience, this behavior ocurrs when execute npm install or npm uninstall in a windows console that not is maximized (cmd, powershell, nodejs command prompt, etc.). I don't know why ocurrs this error, but if we can maximize terminals before execute these commands we can avoid the freezing behavior.

I hope this can help you guys.

Best regards from El Salvador.

@robertwbradford
Copy link

[email protected] did not solve this for us :(

@leoNavarro95
Copy link

I am getting this error as well on a windows PC using the command prompt (cmd.exe). I've tried the following combinations and was able to reproduce the stuckness each time (I was using nvm for windows to switch versions):

node v16.13.1 / npm 8.1.2 node v17.2.0 / npm 8.1.4 node 16.10.0 / npm 7.24.0

I do have AV Defender installed, which I can't disable due to it being a company installed anti-virus software. I was also running Fiddler4 and haven't seen any HTTP errors related.

I then switched to a git bash terminal and was able to run npm install 3 times with version 16.13.1/8.1.2 and no hangs. I also ran npm ci 3 times with no hangs.

My git version installed on windows was 2.17.1.windows.2.

Thanks a lot to mention the git bash terminal solution this save me. I am also ran into this problem that the npm get stuck forever while running on the Windows 10 powershell. So I just ran the npm install in git bash and solved inmediately without any issue.

Now, I wonder why this happens. Please, if anyone knows, I would greatly appreciate it the explanation.

@VibingCreator
Copy link

VibingCreator commented Oct 22, 2024

npm http fetch GET 200 https://registry.npmjs.org/@types%2fd3-array 737ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@types%2fd3-time 1272ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@types%2fd3-ease 1312ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/d3-time-format 52ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/d3-path 79ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/d3-format 82ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/internmap 84ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/d3-color 104ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@types%2fd3-color 122ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@types%2fd3-path 1224ms (cache revalidated)

I have similar issues with NPM recently. It's stuck...

¯_(ツ)_/¯ Switching to pnpm!

@Tofandel
Copy link

Tofandel commented Oct 22, 2024

You can also downgrade npm npm i -g [email protected] instead of switching to pnpm which has is own set of issues as well, the issue starts after 10.4.0

@KrashLeviathan
Copy link

I used a combination of the above comments by @jsbmg and @Tofandel along with nvm to get things to work. Not sure if the versions of node/npm I used are the absolute latest working versions, but I'll take them for now until the bug is resolved in a forthcoming patch. 👀

nvm install 22.5
npm install -g [email protected]
node -v    # output: v22.5.1
npm  -v    # output: 10.3.0

@jmashore
Copy link

jmashore commented Oct 27, 2024

I reverted back to [email protected] and this resolved the issue. It may have been just happenstance but for now, it appears to work properly.

Previous
npm info using [email protected]
npm info using [email protected].

After :
Ubuntu Jammy
npm info using [email protected]
npm info using [email protected]

npm install -g [email protected]

@Tofandel
Copy link

Tofandel commented Oct 28, 2024

I have found the culprit

async #checkEngineAndPlatform () {
const { engineStrict, npmVersion, nodeVersion } = this.options
for (const node of this.idealTree.inventory.values()) {
if (!node.optional) {
try {
// if devEngines is present in the root node we ignore the engines check
if (!(node.isRoot && node.package.devEngines)) {
checkEngine(node.package, npmVersion, nodeVersion, this.options.force)
}
} catch (err) {
if (engineStrict) {
throw err
}
log.warn(err.code, err.message, {
package: err.pkgid,
required: err.required,
current: err.current,
})
}
checkPlatform(node.package, this.options.force)
}

It's coming from checkPlatform which is done in a loop over each node, inside checkPlatform there is this line https://github.com/npm/npm-install-checks/blob/4751cb40207cf48ac21ac041b0c239e3c10d37e0/lib/current-env.js#L24

This line takes 40seconds by itself to execute (node bug) and the fact is that it's also not promisified in the loop so this is done sequentially for all the 2000 packages in the tree, this effectively would take in theory a whole 70 days for my upgrade command to complete (that's a lot of time to wait 😉)

@ljharb
Copy link
Contributor

ljharb commented Oct 28, 2024

It's done concurrently, not sequentially, because it's not awaited in the loop.

@Tofandel
Copy link

Tofandel commented Oct 28, 2024

But it's not async https://github.com/npm/npm-install-checks/blob/main/lib/index.js#L25 so yes it's done sequentially, not concurrently at all, the async keyword in front of #checkEngineAndPlatform does absolutely nothing

@ljharb
Copy link
Contributor

ljharb commented Oct 28, 2024

ah, yes, good point :-)

@Apezdr
Copy link

Apezdr commented Nov 7, 2024

I reverted back to [email protected] and this resolved the issue. It may have been just happenstance but for now, it appears to work properly.

Previous npm info using [email protected] npm info using [email protected].

After : Ubuntu Jammy npm info using [email protected] npm info using [email protected]

npm install -g [email protected]

I had to revert to this version to get my npm install to finish. May end up having to adjust dockerfiles etc. to get this to work for you depending on your use case.

@alexbaileyuk
Copy link

Switching back to npm 10.3.0 worked for me. Was 10.9.0 before that.

@svaraborut
Copy link

This issue is getting serious. We had Docker build pipelines starting to build in more than 20 minutes. We had to downgrade to npm 10.3.0 and builds are now smooth at 60 seconds. The solution was:

FROM node:22-alpine
RUN npm install -g [email protected]
...

@amp42
Copy link

amp42 commented Nov 13, 2024

WSL 2, Ubuntu 22.04 LTS, npm 10.9

Does not work

node 20.9.0
npm install.. hangs on a fetch of some dependency
npm ci hangs
npm cache clear --force does not help

Does work
node 22.10.0

Switch from node 20.9 to 22.10 via nvm: nvm use 22.10.0 . If you don't have 22.10.0, try installing it via nvm.

@fnagel
Copy link

fnagel commented Nov 18, 2024

@Tofandel Thanks for investigating! Any news on when the fix will be available?

@Tofandel
Copy link

Tofandel commented Nov 18, 2024

It's out of my hands unfortunately, I opened a PR in node which has been merged, so likely a few weeks for node 22.12.0 and 20.19.0

For npm there is 2 PR's open, one completely bypassing getReport if possible and one only calling it once before any requests

I do not know the release schedule of npm, I only know they are preparing npm 11 and it seems this issue even though super widespread and which should be handled with high priority did not get much of the members attention for a patch release before the major release

Maybe @reggi can give an answer?

@smoore-dl
Copy link

We've been frustrated by an issue that sounds very similar (or the same) as this one.

We have a bunch of Bamboo jobs that run scripts that use Node. We have a project we use for automated testing that uses a lot of npm libraries. "npm install" used to work fine in Node 14.

We've updated our Bamboo agents to support Node 16 and Node 17. Build jobs that use those versions now have a strange issue:

  • Usually, they run fine, and "npm install" completes in less than 10 sec
  • Sometimes, they hang for up to 10 or 12 minutes before finally completing

I know that 10 or 12 minutes is not the same as "forever." But when you're running a Bamboo build task that usually runs in < 10 sec, and suddenly (randomly) it takes 10 to 12 min, it sure feels like forever!

@knilink
Copy link

knilink commented Nov 21, 2024

[email protected], [email protected] (caused by process.report.getReport() slowness)
found a workaround for hanging at npm ci is to turn off update notification npm config set update-notifier false
it stopped npm from fetching manifest then somehow the issue was magically gone
seem to be only working for reinstalling node modules with existing package-lock.json, installing new module npm i new-module may still hang.

wraithgar pushed a commit to npm/npm-install-checks that referenced this issue Nov 21, 2024
Yes this is a bit dirty because the report is now generated once at the
beginning of a command which could be considered a side effect (but
normally treeshaking will only include it only if needed), but the whole
process.report is a weirdly built API meant for debugging and not really
meant to be used in a normal program

But somehow when the call is done in the beginning of the process, this
call is very fast, but when it's called after having run a http request
(as is currently the case, a single call takes a lot more time to
complete, it takes 40s or more on my system when called at the end of
npm upgrade) but only a few milliseconds when called at the beginning
(this is why it's best to run it outside the function at the beginning
of the process as a side effect instead of calling getReport on demand
and cache the result)

Here is a log of console.time('report') and console.timeEnd('report')
before and after the getReport call
when run in the end of the upgrade command:
⠼report: 3:10.573 (m:ss.mmm)
when run in the beginning of the process at the top level
report: 1.943ms

This fixes npm hanging npm/cli#4028,
npm/cli#7814,
npm/cli#7868
@wraithgar
Copy link
Member

This is not the same bug as the rest that were hanging because of getReport. This issue predates that code.

However, enough folks have reported unrelated similar cases to this issue, making it a catchall for any time npm seemed to hang. It's impossible to sort them out at this point. If you are experiencing npm hanging in the newest version, please open a new issue so we can look at it in isolation.

@HEllRZA
Copy link

HEllRZA commented Nov 25, 2024

I have a similar issue, but not caused from a 40s delay of auditReport() but a ca. 500ms delay of checkPlatform() for every time of the hundreds of times it is called.
I just cashed os, cpu and libc and it solves the issue for me:

[...]/node/v20.17.0/lib/node_modules/npm/node_modules/npm-install-checks/lib/index.js

// Cache default values
const _os = currentEnv.os()
const _cpu = currentEnv.cpu()
const _libc = currentEnv.libc(_os)

const checkPlatform = (target, force = false, environment = {}) => {
  if (force) {
    return
  }
  // Use cached values as fallback
  const os = environment.os || _os;
  const cpu = environment.cpu || _cpu;
  const libc = environment.libc || _libc;

@Tofandel
Copy link

@HEllRZA You are late to the party #4028 (comment)

This is already solved in npm 10.9.1

@lasjdhu
Copy link

lasjdhu commented Nov 26, 2024

Not sure if it helps someone because I had a very specific environment, but in my case hanging while npm install was actually a kernel bug that caused an "uninterruptible deep sleep" process status (NixOS, Linux kernel v6.6.58). I managed to solve this by updating the Linux kernel to version 6.11.6. See related issue in nodejs repo #5587

@FrantisekVrab
Copy link

so, after a days of debugging and trying every possibile solution (mainly reinstalling every possible version of node and npm), with no luck, it was:

i needed to add node.exe to a list of "Allow an app to access controlled folders" since my folder was protected by this windows feature..

im running windows 11

heres how to do it: https://support.microsoft.com/en-us/windows/allow-an-app-to-access-controlled-folders-b5b6627a-b008-2ca2-7931-7e51e912b034

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests