npm / cli

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

[BUG] NPM doesn't allow me to 'npm i' on even slightly weak network connections #4430

Open okirpane opened 2 years ago

okirpane commented 2 years ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

When I run npm i on my computer (Macbook Pro 2020) with a 5G internet connection that drops packages every now and then, the command hangs at larger packages. Basically:

Expected Behavior

I would expect my package manager to at least work when my connection wavers a little. The fact that NPM just fails completely is dissapointing.

Steps To Reproduce

  1. Connect to a slightly unstable network connection
  2. Start a project with some node_modules
  3. Run npm i
  4. Observe that it hangs when it reaches a large package.

Environment

prefix = "/opt/homebrew"

; "project" config from /Users/okirp/Desktop/ojasvin/.npmrc

engine-strict = true

; node bin location = /opt/homebrew/Cellar/node/16.11.0/bin/node ; cwd = /Users/okirp/Desktop/ojasvin ; HOME = /Users/okirp ; Run npm config ls -l to show all defaults.

nlf commented 2 years ago

it's likely what's happening here is a request is timing out, so we're retrying it. by default we'll retry the same package 2 times after the initial failure, so i would expect to see what appears to be npm hanging for the time it takes 3 requests to timeout which is ~15 minutes by default. if you npm i --fetch-timeout=60000 it'll reduce the overall failure time to ~3 minutes, though based on the information provided all that's really going to do is get you to an error quicker.

i'm curious, how large of a package are you seeing this failure with? if you download the package tarball outside of npm (i.e. curl or wget) how long does it take to transfer?

spotlesscoder commented 5 months ago

this is extremely annoying. Happened to me in train again yesterday 2 retries as default is not enough. Sometimes you're offline on train for 5 minutes or more The default retries should be like 10 or so Also, large packages should be fetched in chunks and the chunks should be retried individually