从github安装角度包失败

时间:2019-02-13 10:51:52

标签: git github npm proxy windows-10

我只想从Visual Studio Code终端运行npm install angular-ui-router, 但是失败了。我使用Windows 10,并且在Stackoverflow上的某个地方,我读到问题可能是我使用了不兼容的git版本(2.19.whatever),所以我将git升级到了git version 2.21.0.rc0.windows.1。它仍然不起作用。以下是我得到的堆栈跟踪:

npm ERR! Error while executing:npm ERR! C:\Users\pe\AppData\Local\Programs\Git\cmd\git.EXE ls-remote -h -t git://github.com/nmccready/google-maps-utility-library-v3-markerwithlabel.git
npm ERR!
npm ERR! fatal: unable to connect to github.com:
npm ERR! github.com[0: 140.82.118.3]: errno=No such file or directory
npm ERR! github.com[1: 140.82.118.4]: errno=No such file or directory
npm ERR!
npm ERR!
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\pe\AppData\Roaming\npm-cache\_logs\2019-02-13T10_41_56_811Z-debug.log

甚至npm install -g npm也失败。

npm install -g npm
npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! network request to https://registry.npmjs.org/npm failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443
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:
npm ERR!     C:\Users\pe\AppData\Roaming\npm-cache\_logs\2019-02-13T10_55_40_391Z-debug.log

我猜没有任何与代理相关的问题(即我设置了代理并为'npm get http-proxy'和npm get https-proxy'获得了有意义的值)。 我们非常感谢您的帮助。

3 个答案:

答案 0 :(得分:0)

您需要先设置npm config

npm config set registry http://registry.npmjs.org/

然后您可以执行npm install或安装其他任何软件包。

答案 1 :(得分:0)

我认为在您的终端设置代理可能是导致问题的原因,您是在公司防火墙后面,需要通过代理建立隧道还是在个人计算机上工作?

也许您可以尝试以下方法来查看它是否可以解决您的问题:

  1. 重置您的npm代理:

    npm config rm proxy npm config rm https-proxy

  2. 将您的npm注册表设置为指向npmjs,而无需ssl:

    npm配置集注册表http://registry.npmjs.org/

  3. 再次安装Angular Router:

    npm i angular-ui-router

希望有帮助!

答案 2 :(得分:0)

设置这样的代理很重要:

npm config set https-proxy http://host:port
npm config set proxy http://host:port

将以下内容放在.gitconfig的末尾也很重要

[url "https://"]
    insteadOf = git://
[url "https://github.com"]
    insteadOf = git@github.com

但是,如果您恰巧在Windows 10上,这还不够。 结果(在Windows上)npm将尝试从用户homedir(默认为.gitconfig)中抓取c:\Users\[username]\.gitconfig文件,并且如果将其放在全局配置中,则将忽略全局配置/个人配置不同的位置。将全局配置文件复制到上述位置对我来说解决了这个问题。

https://github.com/phonegap/phonegap-cli/issues/352