Cli: [QUESTION] Is there a way to define timeout for `npm install`

Created on 14 Apr 2020  ·  11Comments  ·  Source: npm/cli

What / Why

For now, we have a problem with the package, which meta info file (where all versions are listed) weights more than 110Mb and it takes 2.5 minutes to download the file on my machine, for our team it causes annoying npm install failed because of

Response timeout while trying to fetch http://regsitry.url/example-meta-file (over 30000ms)

Where

For now, on the local environment, I had to tune npm files, to change the default timeout.
In NPM debug log I found that Response timeout... message comes from
~/.nvm/versions/node/v12.16.1/lib/node_modules/npm/node_modules/node-fetch-npm/src/body.js:189:16
This one sources: https://github.com/npm/node-fetch-npm/blob/latest/src/body.js#L189

I hardcoded that in such a way:

    // allow timeout on slow response body
    if (this.timeout) {
      resTimeout = setTimeout(() => {
        abort = true
        reject(new FetchError(`Response timeout while trying to fetch ${this.url} (over ${this.timeout}ms)`, 'body-timeout'))
-      }, this.timeout)
+      }, 5 * 60* 1000) // 5 minutes timeout to prevent failing on huge meta files downloading
    }

Who

n/a

References

n/a

So the question is:

Is there some parameter/ENV_VARIABLE, that can be passed or be defined before npm install command, which will override this.timeout value in the code that I share.

Bug Needs Discussion Question Release 6.x patch

Most helpful comment

So the current fix is to upgrade to NPM 6.14.5.

It would be perfect when latest Node.js versions (10.x, 12.x, 13.x, 14.x) to be shipped with 6.14.5 instead of 6.14.4:
https://nodejs.org/en/download/releases/

All 11 comments

Also worth mentioning:
couldn't find in code of @npm/cli or node-fetch-npm anything about 30000 which is like the "default timeout" passed to node-fetch-npm somehow

Seems to be used in make-fetch-happen which is used in npm-registry-fetch and pacote. We're running into an issue where the metadata has gotten big enough to push us over 30 seconds in some environments.

There still doesn't seem to be a way to configure the magic timeout option - https://github.com/npm/cli/blob/latest/lib/fetch-package-metadata.js#L56-L58

Same here I post it on ionic cli github
https://github.com/ionic-team/ionic-cli/issues/4387

downgrading to 6.13.x resolved it for me - https://github.com/npm/cli/commit/ea0ff56cb6ad4bbf208dd3cf39a35e07fc2dff16#diff-3c78131ed196efbd3ce9fdee2df36e24R79

@darcyclarke for now, we get more problems because of that, cause latest Node.js v12.16.2 was shipped with NPM v6.14.x by default.

Seems like upgrading npm-registry-fetch in NPM v6.14.0 caused our problem with a timeout as @darrinholst mentioned earlier:
https://github.com/npm/cli/commit/ea0ff56cb6ad4bbf208dd3cf39a35e07fc2dff16

Without the ability to redefine timeout for that npm-registry-fetch in NPM v6.14.x, we had to fixate Node.js version to 12.16.1 as it is the last version with NPM v6.13.x.

And seems like it is a bug, cause before that changes https://github.com/npm/cli/commit/ea0ff56cb6ad4bbf208dd3cf39a35e07fc2dff16#diff-acf38193ec0e2d9a3b9dc202f239a77aR12, huge meta-files was not a problem at all.

@sidoruk-sv appreciate you bringing this to our attention. I'm going to take this back internally & see if we can ship a patch to resolve this &/or find/introduce a flag.

We are unable to deploy our project, most often webpack meta file does timeout, sometimes firebase. It got worse the last weeks, seems the meta file now reached a point were it is consistantly failing. We will try to downgrade to 6.13.7.

Edit: after downgrading we got the first green build after 10+ fails, looks promising.

See https://github.com/npm/npm-registry-fetch/issues/26

Let's move the default timeout back to zero for nrf v4 (npm v6), bump it up to 5m in latest (npm v7), and add a --fetch-timeout option in the CLI v7 to set this explicitly.

I think that'd solve the immediate issue and put us in a better spot going forward.

So the current fix is to upgrade to NPM 6.14.5.

It would be perfect when latest Node.js versions (10.x, 12.x, 13.x, 14.x) to be shipped with 6.14.5 instead of 6.14.4:
https://nodejs.org/en/download/releases/

the npm config documentation has several entries for timeouts. Is this code ignoring those settings, or is there no setting for this specific case and that's the issue?

is there no setting for this specific case and that's the issue?

yes, option should be coming in v7

Was this page helpful?
0 / 5 - 0 ratings