繁体   English   中英

如何解决 npm 安装问题?

[英]How to fix npm installation issue?

我正在尝试安装 npm 包

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)

我尝试将 npm 配置重置为默认值。 我也尝试使用/退出 vpn 进行安装,但仍然无法正常工作..

这是配置:

; 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"

我在尝试解决此问题时设置了这些值,但仍然无效。 我可能需要说 npm 之前运行良好..

为了回答您的问题,您在连接registry.npmjs.org时遇到了问题。

尝试触发以下命令(考虑您正在使用Windows)。

  1. ping Registry.npmjs.org

  2. traceroute -n Registry.npmjs.org

如果第一个命令返回“ Destination Host Unreachable”,则说明您位于防火墙之后,并且阻止了您访问服务器。

此外,您可以检查.npmrc条目或npm config ls

我在ubuntu (wsl)上遇到了同样的问题。

试试这些:

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

如果ping不成功,有多种选择:

  1. 检查您的连接
  2. 检查你的防火墙
  3. 检查您的代理

对我来说,它是代理,我不得不禁用选项自动检测设置

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM