【问题标题】:How to fix npm installation issue?如何解决 npm 安装问题?
【发布时间】:2019-11-16 14:06:46
【问题描述】:

我正在尝试安装 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 配置重置为默认值。我也试过用/out 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 之前运行良好..

【问题讨论】:

    标签: node.js npm npm-install


    【解决方案1】:

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

    试试下面的命令(考虑到你使用的是windows)。

    1. ping registry.npmjs.org

    2. traceroute -n registry.npmjs.org

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

    您还可以检查您的 .npmrc 条目或 npm config ls

    【讨论】:

      【解决方案2】:

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

      试试这些:

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

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

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

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

      【讨论】:

        猜你喜欢
        • 2020-06-29
        • 2020-12-22
        • 2021-10-11
        • 2021-07-14
        • 2021-03-06
        • 1970-01-01
        • 1970-01-01
        • 2022-06-10
        • 2021-12-22
        相关资源
        最近更新 更多