安装grunt时出现NodeJS NPM代理错误

Ant*_*lin 19 proxy node.js npm gruntjs

当我尝试安装gruntvia时npm,我收到以下错误:

C:\Program Files\nodejs\node_modules\npm>npm install -g grunt
npm ERR! network connect ETIMEDOUT
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is 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! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "grunt"
npm ERR! cwd C:\Program Files\nodejs\node_modules\npm
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! syscall connect
npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\Program Files\nodejs\node_modules\npm\npm-debug.log
npm ERR! not ok code 0
Run Code Online (Sandbox Code Playgroud)

我正在使用企业代理配置,我相信由于其配置,我遇到了这个错误.为了成功安装grunt,我需要更改什么?

Kan*_*cor 22

您需要配置npm配置文件,这可以在终端中完成:

npm config set proxy http://proxy.company.com:8080

npm config set https-proxy http://proxy.company.com:8080
Run Code Online (Sandbox Code Playgroud)

您的错误日志建议看到'npm help config',所以我认为问题来自那里.

如果您想要更多解释的链接,请参阅此博客条目(还有更多)

祝好运!


小智 10

如果您在"Windows"域中的代理后面工作,请将域名添加到代理URL中:

npm config set proxy http://domain%5Cuser:password@proxy.company.com:8080
npm config set https-proxy http://domain%5Cuser:password@proxy.company.com:8080
Run Code Online (Sandbox Code Playgroud)

您需要将反斜杠编码为http uri字符串:%5C

如果您的用户名或密码中有特殊字符,则还需要对这些字符进行编码.请记住,这些关键信息以纯文本形式存储在npm配置文件(%HOME%\.npmrc)中.也可能需要将npm注册表指向http源:

npm config set registry "http://registry.npmjs.org"
npm config set strict-ssl false
Run Code Online (Sandbox Code Playgroud)


Dev*_*kec 6

这个配置适合我.您需要检查您的http和https端口(通常它们分别是80和443),但在我的情况下,我使用的是端口80.

npm config set proxy http://user:password@proxy.url.com:80

npm config set https-proxy http://user:password@proxy.url.com:80
Run Code Online (Sandbox Code Playgroud)

您可以通过get命令检查代理设置

npm config get proxy

npm config get https-proxy
Run Code Online (Sandbox Code Playgroud)


shi*_*tab 6

我之前遇到过同样的问题,因为我错误地使用了代理配置,如下所示:

npm config set proxy http://localhost:8080/ npm config set https-proxy http://localhost:8080/ npm config set strict-ssl false

这使得 npm 客户端尝试点击 localhost:8080 来拉取模块而不是正确的互联网端点。

所以经过几天的挫折后,我找到了这个链接 https://docs.npmjs.com/cli/config

它告诉你跑

 npm config edit
Run Code Online (Sandbox Code Playgroud)

这打开了一个文件,在该文件中,我删除了上面添加的那三行,是的,一切正常。ALH 希望有帮助。