cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] ENETUNREACH errors during npm install -> dep from github

Open dhoko opened this issue 4 years ago • 6 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

👋 I have this bug inside our CI with http_proxy set it's impossible to have npm to work. It seems it's not able to handle the proxy anymore (upgrade/change of the lib doing requests?)

npm ci does not work.

$ npm --version
8.3.0
$ npm ci --no-audit
npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /usr/bin/node /usr/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/root/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm ERR! code 1
npm ERR! npm ERR! path /root/.npm/_cacache/tmp/git-clonezsHhpF/node_modules/tree-sitter-cli
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c node install.js
npm ERR! npm ERR! Downloading https://github.com/tree-sitter/tree-sitter/releases/download/v0.20.0/tree-sitter-linux-x64.gz
npm ERR! npm ERR! node:events:368
npm ERR! npm ERR!       throw er; // Unhandled 'error' event
npm ERR! npm ERR!       ^
npm ERR! npm ERR! 
npm ERR! npm ERR! Error: connect ENETUNREACH 140.82.113.4:443
npm ERR! npm ERR!     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16)
npm ERR! npm ERR! Emitted 'error' event on ClientRequest instance at:
npm ERR! npm ERR!     at TLSSocket.socketErrorListener (node:_http_client:447:9)
npm ERR! npm ERR!     at TLSSocket.emit (node:events:390:28)
npm ERR! npm ERR!     at emitErrorNT (node:internal/streams/destroy:157:8)
npm ERR! npm ERR!     at emitErrorCloseNT (node:internal/streams/destroy:122:3)
npm ERR! npm ERR!     at processTicksAndRejections (node:internal/process/task_queues:83:21) {
npm ERR! npm ERR!   errno: -101,
npm ERR! npm ERR!   code: 'ENETUNREACH',
npm ERR! npm ERR!   syscall: 'connect',
npm ERR! npm ERR!   address: '140.82.113.4',
npm ERR! npm ERR!   port: 443
npm ERR! npm ERR! }
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /root/.npm/_logs/2021-12-13T14_41_06_064Z-debug-0.log
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-12-13T14_40_34_553Z-debug-0.log

It's a major regression.

Expected Behavior

npm ci :heavy_check_mark: as it does with npm@6 for the same version of Node.

Steps To Reproduce

:information_source: we're inside a CI with http_proxy and https_proxy If we read the doc, it should be fine https://docs.npmjs.com/cli/v8/using-npm/config#https-proxy

  1. Install npm 6
  2. Use the package.json + rename lock6.json to package-lock.json
  3. Run npm ci
  4. It works

  1. Install npm 8
  2. Use the package.json + rename lock6.json to package-lock.json or take the pacakge-lock.json
  3. Run npm ci
  4. It breaks

Demo repo https://github.com/dhoko/bug-npm with with 3 files:

  • package.json
  • package-lock.json (made with npm 8)
  • lock6.json (lockfile made with npm 6)

I found this issue https://github.com/npm/cli/issues/2983 which seems similar as the issue comes with what's after npm 6.

Thx 🙏

Environment

  • npm: 8.3.0
  • Node: 16.11.1
  • OS: debian stable
  • platform: CI
  • npm config:
$ npm config ls
; node bin location = /usr/bin/node
; cwd = /builds/xxx/find-app-dependencies
; HOME = /root
; Run `npm config ls -l` to show all defaults.
$ npm config ls -l
; "default" config from default values
_auth = (protected) 
access = null 
all = false 
allow-same-version = false 
also = null 
audit = true 
audit-level = null 
auth-type = "legacy" 
before = null 
bin-links = true 
browser = null 
ca = null 
cache = "/root/.npm" 
cache-max = null 
cache-min = 0 
cafile = null 
call = "" 
cert = null 
ci-name = "gitlab" 
cidr = null 
color = true 
commit-hooks = true 
depth = null 
description = true 
dev = false 
diff = [] 
diff-dst-prefix = "b/" 
diff-ignore-all-space = false 
diff-name-only = false 
diff-no-prefix = false 
diff-src-prefix = "a/" 
diff-text = false 
diff-unified = 3 
dry-run = false 
editor = "vi" 
engine-strict = false 
fetch-retries = 2 
fetch-retry-factor = 10 
fetch-retry-maxtimeout = 60000 
fetch-retry-mintimeout = 10000 
fetch-timeout = 300000 
force = false 
foreground-scripts = false 
format-package-lock = true 
fund = true 
git = "git" 
git-tag-version = true 
global = false 
global-style = false 
globalconfig = "/usr/etc/npmrc" 
heading = "npm" 
https-proxy = null 
if-present = false 
ignore-scripts = false 
include = [] 
include-staged = false 
include-workspace-root = false 
init-author-email = "" 
init-author-name = "" 
init-author-url = "" 
init-license = "ISC" 
init-module = "/root/.npm-init.js" 
init-version = "1.0.0" 
init.author.email = "" 
init.author.name = "" 
init.author.url = "" 
init.license = "ISC" 
init.module = "/root/.npm-init.js" 
init.version = "1.0.0" 
json = false 
key = null 
legacy-bundling = false 
legacy-peer-deps = false 
link = false 
local-address = null 
location = "user" 
lockfile-version = null 
loglevel = "notice" 
logs-max = 10 
; long = false ; overridden by cli
maxsockets = 15 
message = "%s" 
metrics-registry = "https://registry.npmjs.org/" 
node-options = null 
node-version = "v16.13.0" 
noproxy = [""] 
npm-version = "8.1.0" 
offline = false 
omit = [] 
only = null 
optional = null 
otp = null 
pack-destination = "." 
package = [] 
package-lock = true 
package-lock-only = false 
parseable = false 
prefer-offline = false 
prefer-online = false 
prefix = "/usr" 
preid = "" 
production = null 
progress = false 
proxy = null 
read-only = false 
rebuild-bundle = true 
registry = "https://registry.npmjs.org/" 
save = true 
save-bundle = false 
save-dev = false 
save-exact = false 
save-optional = false 
save-peer = false 
save-prefix = "^" 
save-prod = false 
scope = "" 
script-shell = null 
searchexclude = "" 
searchlimit = 20 
searchopts = "" 
searchstaleness = 900 
shell = "sh" 
shrinkwrap = true 
sign-git-commit = false 
sign-git-tag = false 
sso-poll-frequency = 500 
sso-type = "oauth" 
strict-peer-deps = false 
strict-ssl = true 
tag = "latest" 
tag-version-prefix = "v" 
timing = false 
tmp = "/tmp" 
umask = 0 
unicode = false 
update-notifier = true 
usage = false 
user-agent = "npm/{npm-version} node/{node-version} {platform} {arch} workspaces/{workspaces} {ci}" 
userconfig = "/root/.npmrc" 
version = false 
versions = false 
viewer = "man" 
which = null 
workspace = [] 
workspaces = null 
yes = null 
; "cli" config from command line options
long = true

yes inside node and npm are not the same, because I tested severals version before making the issue. Only way to fix this issue is to rollback to npm@6

dhoko avatar Dec 13 '21 15:12 dhoko

For me, broken on npm 8.5.2 with nodejs v17.7.1 and works on npm 8.5.0 with nodejs v16.14.2 Even on empty folder

npm 8.5.2
❯ npm17 -v
8.5.2

❯ cat $(readlink -f $(which npm17))
#!/usr/bin/node17
require('../lib/cli.js')(process)

❯ node17 -v
v17.7.1

❯ npm cache clean --force
❯ ls -a
.  ..

❯ npm17 i npm-dummy-package
npm ERR! code ENETUNREACH
npm ERR! syscall connect
npm ERR! errno ENETUNREACH
npm ERR! request to https://registry.npmjs.org/npm-dummy-package failed, reason: connect ENETUNREACH 2606:4700::6810:1a23:443

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/nixi/.npm/_logs/2022-05-15T13_41_25_855Z-debug-0.log
npm 8.5.0
❯ npm16 -v
8.5.0

❯ cat $(readlink -f $(which npm16))
#!/usr/bin/node16
require('../lib/cli.js')(process)

❯ node16 -v
v16.14.2

❯ npm cache clean --force
❯ ls -a
.  ..

❯ npm16 i npm-dummy-package

added 1 package, and audited 2 packages in 2s

found 0 vulnerabilities

I use OpenSUSE Tumbleweed and install node&npm using zypper

zypper info nodejs17 npm17
Information for package nodejs17:
---------------------------------
Repository     : Main Repository (OSS)
Name           : nodejs17
Version        : 17.7.1-1.5
Arch           : x86_64
Vendor         : openSUSE
Installed Size : 32,4 MiB
Installed      : Yes (automatically)
Status         : up-to-date
Source package : nodejs17-17.7.1-1.5.src
Upstream URL   : https://nodejs.org
Summary        : Evented I/O for V8 JavaScript
Description    : 
    Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js
    uses an event-driven, non-blocking I/O model. Node.js has a package ecosystem
    provided by npm.


Information for package npm17:
------------------------------
Repository     : Main Repository (OSS)
Name           : npm17
Version        : 17.7.1-1.5
Arch           : x86_64
Vendor         : openSUSE
Installed Size : 7,8 MiB
Installed      : Yes (automatically)
Status         : up-to-date
Source package : nodejs17-17.7.1-1.5.src
Upstream URL   : https://nodejs.org
Summary        : Package manager for Node.js
Description    : 
    A package manager for Node.js that allows developers to install and
    publish packages to a package registry.
zypper info nodejs16 npm16
Information for package nodejs16:
---------------------------------
Repository     : Main Repository (OSS)
Name           : nodejs16
Version        : 16.14.2-1.3
Arch           : x86_64
Vendor         : openSUSE
Installed Size : 31,1 MiB
Installed      : Yes (automatically)
Status         : up-to-date
Source package : nodejs16-16.14.2-1.3.src
Upstream URL   : https://nodejs.org
Summary        : Evented I/O for V8 JavaScript
Description    : 
    Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js
    uses an event-driven, non-blocking I/O model. Node.js has a package ecosystem
    provided by npm.


Information for package npm16:
------------------------------
Repository     : Main Repository (OSS)
Name           : npm16
Version        : 16.14.2-1.3
Arch           : x86_64
Vendor         : openSUSE
Installed Size : 7,8 MiB
Installed      : Yes
Status         : up-to-date
Source package : nodejs16-16.14.2-1.3.src
Upstream URL   : https://nodejs.org
Summary        : Package manager for Node.js
Description    : 
    A package manager for Node.js that allows developers to install and
    publish packages to a package registry.

psydvl avatar May 15 '22 13:05 psydvl

:wave:

I'm coming back because it's still there:

  • debian testing
  • node v18.16.0
  • npm v9.5.1

I isolated the module in a fork

$ env | grep -i -E 'http(s?)_'
https_proxy=http://xxx/
http_proxy=http://xxx/

Test clone and run the script

$ curl -L https://github.com/dhoko/tree-sitter-cli/archive/refs/heads/master.zip -o tree-sitter-cli-master.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  6475    0  6475    0     0  10081      0 --:--:-- --:--:-- --:--:-- 31432
$ unzip tree-sitter-cli-master.zip
Archive:  tree-sitter-cli-master.zip
d98410431ccc47b862272ef88ad7a4efb0247d2c
   creating: tree-sitter-cli-master/
  inflating: tree-sitter-cli-master/.gitignore  
  inflating: tree-sitter-cli-master/cli.js  
  inflating: tree-sitter-cli-master/dsl.d.ts  
  inflating: tree-sitter-cli-master/install.js  
  inflating: tree-sitter-cli-master/package.json  
$ (cd tree-sitter-cli-master && node install.js)
Downloading https://github.com/tree-sitter/tree-sitter/releases/download/v0.20.8/tree-sitter-linux-x64.gz

As you can see it works fine, no errors.

Install using npm

$ npm i github:dhoko/tree-sitter-cli#master || echo "OK"
npm WARN skipping integrity check for git dependency ssh://[email protected]/tree-sitter/tree-sitter-typescript.git 
npm WARN skipping integrity check for git dependency ssh://[email protected]/tree-sitter/tree-sitter-javascript.git 
npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /usr/bin/node /usr/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/root/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm ERR! code 1
npm ERR! npm ERR! path /root/.npm/_cacache/tmp/git-cloneqDtfVq/node_modules/tree-sitter-cli
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c node install.js
npm ERR! npm ERR! Downloading https://github.com/tree-sitter/tree-sitter/releases/download/v0.20.0/tree-sitter-linux-x64.gz
npm ERR! npm ERR! node:events:491
npm ERR! npm ERR!       throw er; // Unhandled 'error' event
npm ERR! npm ERR!       ^
npm ERR! npm ERR! 
npm ERR! npm ERR! Error: connect ENETUNREACH 140.82.121.3:443
npm ERR! npm ERR!     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)
npm ERR! npm ERR! Emitted 'error' event on ClientRequest instance at:
npm ERR! npm ERR!     at TLSSocket.socketErrorListener (node:_http_client:502:9)
npm ERR! npm ERR!     at TLSSocket.emit (node:events:513:28)
npm ERR! npm ERR!     at emitErrorNT (node:internal/streams/destroy:151:8)
npm ERR! npm ERR!     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR! npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
npm ERR! npm ERR!   errno: -101,
npm ERR! npm ERR!   code: 'ENETUNREACH',
npm ERR! npm ERR!   syscall: 'connect',
npm ERR! npm ERR!   address: '140.82.121.3',
npm ERR! npm ERR!   port: 443
npm ERR! npm ERR! }
npm ERR! npm ERR! 
npm ERR! npm ERR! Node.js v18.16.0
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /root/.npm/_logs/2023-06-22T15_11_19_284Z-debug-0.log
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-06-22T15_11_02_629Z-debug-0.log
OK

:boom: It fails.

And it's not an issue with the env variables, they are there I made many tests and yep when it's from the hook post install I can still see my proxy vars inside the script.

ex:

$ npm i github:dhoko/tree-sitter-cli#master || echo "OK"
npm WARN skipping integrity check for git dependency ssh://[email protected]/tree-sitter/tree-sitter-typescript.git 
npm WARN skipping integrity check for git dependency ssh://[email protected]/tree-sitter/tree-sitter-javascript.git 
npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /usr/bin/node /usr/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/root/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! > [email protected] install
npm ERR! > node install.js
npm ERR! 
npm ERR! Downloading https://github.com/tree-sitter/tree-sitter/releases/download/v0.20.8/tree-sitter-linux-x64.gz
npm ERR! { proxyEnv: 'http://xxx' }
npm ERR! {
npm ERR!   envs: [
npm ERR!     [ 'https_proxy', 'http://xxx' ],
npm ERR!     [ 'http_proxy', 'http://xxx' ]
npm ERR!   ]
npm ERR! }
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! /root/.npm/_cacache/tmp/git-cloneDHzL5s/install.js:127
npm ERR! throw new Error(`putain de debug ${proxyEnv} - {envs}`)
npm ERR! ^
npm ERR! 
npm ERR! Error: putain de debug http://xxx - {envs}
npm ERR!     at Object.<anonymous> (/root/.npm/_cacache/tmp/git-cloneDHzL5s/install.js:127:7)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1254:14)
npm ERR!     at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
npm ERR!     at Module.load (node:internal/modules/cjs/loader:1117:32)
npm ERR!     at Module._load (node:internal/modules/cjs/loader:958:12)
npm ERR!     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
npm ERR!     at node:internal/main/run_main_module:23:47
npm ERR! 
npm ERR! Node.js v18.16.0
npm ERR! npm ERR! code 1
npm ERR! npm ERR! path /root/.npm/_cacache/tmp/git-cloneDHzL5s
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c node install.js
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /root/.npm/_logs/2023-06-22T14_50_45_375Z-debug-0.log
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-06-22T14_50_29_165Z-debug-0.log
OK

What's going on?

dhoko avatar Jun 22 '23 15:06 dhoko

We had the same error with npm 9.8.1 (the latest build).

We had some git packages working and a package resulting in a 401. After investigating, it seems that when the git library package.json contains scripts, the installation process fails.

It seems it's related to this https://github.com/npm/pacote/blob/main/lib/git.js#L173

If there is a build, or prepare tag, then, a ne NPM context is created. However, this context is missing .npmrc configuration

baptistejamin avatar Aug 03 '23 12:08 baptistejamin

I have notice that it happens when local network has IPv6, but there's no external IPv6 access.

So NPM tries to get repositories using IPv6, but it is accessible by IPv4 only

Node v18.18.2 NPM 10.1.0

a2nt avatar Oct 24 '23 22:10 a2nt

Upgraded node to v20.9.0 and now it works ok

a2nt avatar Oct 26 '23 17:10 a2nt

it doesnt seem to work , ive been trying to install next for the past 4hr now and im still encountering this error : npm install npm WARN deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. npm WARN deprecated [email protected]: Rimraf versions prior to v4 are no longer supported npm ERR! code ETIMEDOUT npm ERR! syscall read npm ERR! errno -110 npm ERR! network read ETIMEDOUT 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. npm ERR! network npm ERR! network If you are behind a proxy, please make sure that the npm ERR! network 'proxy' config is set properly. See: 'npm help config'

npm ERR! A complete log of this run can be found in: /home/w3b/.npm/_logs/2024-09-09T12_27_03_253Z-debug-0.log

and i know my internet connection is very good , im just frustrated about this , even after working , npm run dev would just terminate without error

urah001 avatar Sep 09 '24 12:09 urah001