可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
When I'm trying to install grunt
via npm
, I'm getting a following error:
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?
回答1:
You need to configure the npm config file, this can be done in the terminal:
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.
If you want a link with more explanation see this blog entry (there are plenty more)
Good luck!
回答2:
If you are working behind a proxy in a "windows" domain, add the domain name into the proxy 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
You need to encode the backslash as a http uri string: %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 config set registry "http://registry.npmjs.org"
npm config set strict-ssl false
回答3:
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.
npm config set proxy http://user:password@proxy.url.com:80
npm config set https-proxy http://user:password@proxy.url.com:80
You can check your proxy settings by get
command
npm config get proxy
npm config get https-proxy
回答4:
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
which made npm client attempts to hit localhost:8080 to pull the module rather than the correct internet endpoint.
so after couple of days of frustration i visited this link
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.
回答5:
please use
npm config set proxy http://xx.aa.bb.cc:port
it worked for me
thanks a lot !
回答6:
run >> npm config edit
after open config file in editor, remove following lines
registry=http://registry.npmjs.org/
https-proxy=http://host/:port
strict-ssl=false
回答7:
Below options made it work for me:
npm config set registry "http://registry.npmjs.org"
npm config set proxy http://user:password@proxy.url.com:proxy-port
npm config set strict-ssl false
npm install -g -d yo
回答8:
you can run this in 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
proxy =http://proxy.company.com:8080
https-proxy = http://proxy.company.com:8080
reference
回答9:
The three thing to make npm working well inside the proxy network .
This set npm registry , By default it may take https.
npm config set registry "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"
回答10:
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/