1

I'm trying to install npm package

npm ERR! code EHOSTUNREACH
npm ERR! errno EHOSTUNREACH
npm ERR! request to https://registry.npmjs.org/express-session failed, reason: connect EHOSTUNREACH 104.16.23.35:443 - Local (192.0.108.1:52659)

I tried resetting npm configuration to the default values. I also tried installing with/out vpn, but still didn't work..

Here is the configuration:

; userconfig /Users/mac/.npmrc
 access = null
 allow-same-version = false
 also = null
 always-auth = false
 audit = true
 audit-level = "low"
 auth-type = "legacy"
 before = null
 bin-links = true
 browser = null
 ca = null
 cache = "/Users/mac/.npm"
 cache-lock-retries = 10
 cache-lock-stale = 60000
 cache-lock-wait = 10000
 cache-max = 0
 cache-min = 10
 cafile = "/Users/mac/Projects/NodeProjects/Bloggy/undefined"
 cert = null
 cidr = null
 color = true
 commit-hooks = true
 depth = 0
 description = true
 dev = false
 dry-run = false
 editor = "vi"
 engine-strict = false
 fetch-retries = 2
 fetch-retry-factor = 10
 fetch-retry-maxtimeout = 60000
 fetch-retry-mintimeout = 10000
 force = false
 git = "git"
 git-tag-version = true
 global = false
 global-style = false
 globalconfig = "/usr/local/etc/npmrc"
 globalignorefile = "/usr/local/etc/npmignore"
 group = 20
 ham-it-up = false
 heading = "npm"
 https-proxy = null
 if-present = false
 ignore-prepublish = false
 ignore-scripts = false
 init-author-email = ""
 init-author-name = ""
 init-author-url = ""
 init-license = "ISC"
 init-module = "/Users/mac/.npm-init.js"
 init-version = "1.0.0"
 json = false
 key = null
 legacy-bundling = false
 link = false
 local-address = undefined
 loglevel = "notice"
 logs-max = 10
 long = false
 maxsockets = 50
 message = "%s"
 node-options = null
 node-version = "10.15.3"
 noproxy = null
 offline = false
 onload-script = null
 only = null
 optional = true
 otp = null
 package-lock = true
 package-lock-only = false
 parseable = false
 prefer-offline = false
 prefer-online = false
 prefix = "/usr/local"
 preid = ""
 production = false
 progress = true
 proxy = null
 read-only = false
 rebuild-bundle = true
 registry = "https://registry.npmjs.org/"
 rollback = true
 save = true
 save-bundle = false
 save-dev = false
 save-exact = false
 save-optional = false
 save-prefix = "^"
 save-prod = false
 scope = ""
 script-shell = null
 scripts-prepend-node-path = "warn-only"
 searchexclude = null
 searchlimit = 20
 searchopts = ""
 searchstaleness = 900
 send-metrics = false
 shell = "/bin/bash"
 shrinkwrap = true
 sign-git-commit = false
 sign-git-tag = false
 sso-poll-frequency = 500
 sso-type = "oauth"
 strict-ssl = true
 tag = "latest"
 tag-version-prefix = "v"
 timing = false
 tmp = "/var/folders/qc/f1s84bcj5y10v57pvz0s4st40000gn/T"
 umask = 18
 unicode = true
 unsafe-perm = true
 update-notifier = true
 usage = false
 user = 0
 userconfig = "/Users/mac/.npmrc"
 version = false
 versions = false
 viewer = "man"

I set these values while trying to fix this problem, but still doesn't work. I may need to say that npm was working perfectly before..

Salma
  • 26
  • 1
  • 6

3 Answers3

2

In my case (Fedora 37), the issue wasn't proxy, firewall, or routing. Turns out that having IPv6 turned on in my wired connection had everything (occasionally? partially?) going through the IPv6 address rather than the traditional IPv4.

The simple fix was to turn off IPv6, restart that network connection, and everything just cruised along like greased lightning.

From the original question, this was not their problem (they listed IPv4 addresses), but I hope this answer saves someone else time when they come across this SO question.

1

To answer your question, you have a problem with connecting registry.npmjs.org.

Try firing below commands(considering you are using windows).

  1. ping registry.npmjs.org

  2. traceroute -n registry.npmjs.org

if the first command returns "Destination Host Unreachable", you are behind the firewall and its blocking you reaching to the server.

Further you can check your .npmrc entries or npm config ls

Dean Winchester
  • 352
  • 3
  • 7
1

I had the same problem on ubuntu (wsl).

Try these:

$ ping registry.npmjs.org
$ npm view npm version

If the ping is not successful, there are multiple options:

  1. check your connection
  2. check your firewall
  3. check your proxy

For me it was the proxy and I had to disable the option Detect automaticaly the settings

lejlun
  • 4,140
  • 2
  • 15
  • 31
TristanB12
  • 11
  • 1