安装 grunt 时出现 NodeJS NPM 代理错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26989401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NodeJS NPM Proxy error when installing grunt
提问by Anton Selin
When I'm trying to install gruntvia npm, I'm getting a following error:
当我尝试安装grunt通过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
I′m using enterprise proxy configurations, and I believe that I'm having this error because of its configurations. What do I need to change in order to install grunt successfully?
我正在使用企业代理配置,并且我相信由于其配置而出现此错误。为了成功安装 grunt,我需要更改什么?
回答by Kangcor
You need to configure the npm config file, this can be done in the terminal:
您需要配置 npm 配置文件,这可以在终端中完成:
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
Your error log suggests to see 'npm help config', so i think the problem comes from there.
您的错误日志建议查看“npm help config”,所以我认为问题来自那里。
If you want a link with more explanation see this blog entry(there are plenty more)
如果您想要更多解释的链接,请参阅此博客条目(还有更多)
Good luck!
祝你好运!
回答by Philipp Tschachtschal
If you are working behind a proxy in a "windows" domain, add the domain name into the proxy url:
如果您在“windows”域中的代理后面工作,请将域名添加到代理 url 中:
npm config set proxy http://domain%5Cuser:[email protected]:8080
npm config set https-proxy http://domain%5Cuser:[email protected]:8080
You need to encode the backslash as a http uri string: %5C
您需要将反斜杠编码为 http uri 字符串:%5C
If there are special characters in your username or password, it is necessary to encode these character as well. Keep in mind that these critical informations are stored as plain text in the npm config file (%HOME%\.npmrc). It could also be necessary to point the npm registry to the http source:
如果您的用户名或密码中有特殊字符,也需要对这些字符进行编码。请记住,这些关键信息以纯文本形式存储在 npm 配置文件 (%HOME%\.npmrc) 中。也可能需要将 npm 注册表指向 http 源:
npm config set registry "http://registry.npmjs.org"
npm config set strict-ssl false
回答by Devnegikec
This configuration works for me. You need to check your http and https ports (usually they are 80 and 443 respectively), but in my case I am using port 80 for both.
这个配置对我有用。您需要检查您的 http 和 https 端口(通常它们分别是 80 和 443),但在我的情况下,我同时使用端口 80。
npm config set proxy http://user:[email protected]:80
npm config set https-proxy http://user:[email protected]:80
You can check your proxy settings by getcommand
您可以通过get命令检查您的代理设置
npm config get proxy
npm config get https-proxy
回答by shireef khatab
I had same issue before because I played with proxy configuration by mistake like this :
我之前遇到过同样的问题,因为我错误地使用了代理配置,如下所示:
npm config set proxy http://localhost:8080/
npm config set https-proxy http://localhost:8080/
npm config set strict-ssl false
npm config set proxy http://localhost:8080/
npm config set https-proxy http://localhost:8080/
npm config set strict-ssl false
which made npm client attempts to hit localhost:8080 to pull the module rather than the correct internet endpoint.
这使得 npm 客户端尝试点击 localhost:8080 来拉取模块而不是正确的互联网端点。
so after couple of days of frustration i visited this link
所以经过几天的挫折后,我访问了这个链接
https://docs.npmjs.com/cli/config
https://docs.npmjs.com/cli/config
then run
然后运行
npm config edit
which opened a file. inside that file i removed those three lines i added above , then everything worked fine.
它打开了一个文件。在该文件中,我删除了上面添加的那三行,然后一切正常。
回答by Shubham Rana
please use npm config set proxy http://xx.aa.bb.cc:portit worked for me thanks a lot !
请使用 npm config set proxy http://xx.aa.bb.cc:port它对我有用,非常感谢!
回答by Ranjit Kumar
run >> npm config edit
运行 >> npm 配置编辑
after open config file in editor, remove following lines
在编辑器中打开配置文件后,删除以下几行
registry=http://registry.npmjs.org/
注册表= http://registry.npmjs.org/
https-proxy=http://host/:port
https-proxy= http://host/:port
strict-ssl=false
严格 ssl=false
回答by Dean Jain
Below options made it work for me:
以下选项使其对我有用:
npm config set registry "http://registry.npmjs.org"
npm 配置设置注册表“ http://registry.npmjs.org”
npm config set proxy http://user:[email protected]:proxy-port
npm 配置设置代理http://user:[email protected]:proxy-port
npm config set strict-ssl false
npm 配置设置严格的 SSL 假
npm install -g -d yo
npm install -g -d 哟
回答by Elbaz
you can run this in cmd
你可以在cmd中运行这个
npm config set <key> <value> [-g|--global]
npm config get <key>
npm config delete <key>
npm config list
npm config edit
npm get <key>
npm set <key> <value> [-g|--global]
npmrc.txt will run you can change your link and port
npmrc.txt 将运行您可以更改您的链接和端口
proxy =http://proxy.company.com:8080
https-proxy = http://proxy.company.com:8080
回答by Himanshu sharma
The three thing to make npm working well inside the proxy network .
使 npm 在代理网络中运行良好的三件事。
This set npm registry , By default it may take https.
这个设置 npm registry ,默认情况下它可能需要 https。
npm config set registry "http://registry.npmjs.org/"
npm 配置设置注册表“ http://registry.npmjs.org/”
Second is two set proxy in your system . If your organization use proxy or you.
其次是您系统中的两套代理。如果您的组织使用代理或您。
npm config set proxy "http://username:password@proxy-url:proxy-port"
npm config set https-proxy "http://username:password@proxy-url:proxy-port"
npm 配置设置代理“ http://username:password@proxy-url:proxy-port”
npm 配置设置 https-proxy " http://username:password@proxy-url:proxy-port"
回答by tjp69
If you're frustrated and none of this monkey-business is working for you, just go Download and run the latest MSI. https://nodejs.org/en/download/
如果您感到沮丧,并且这些猴子业务都不适合您,只需下载并运行最新的 MSI。 https://nodejs.org/en/download/

