简体   繁体   中英

NodeJS NPM Proxy error when installing grunt

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?

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!

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

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

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 found this link https://docs.npmjs.com/cli/config

which tells you to run

 npm config edit

That opened a file, inside that file i removed those three lines i added above , and yes, everything worked fine. ALH Hope that helps.

请使用 npm config set proxy http://xx.aa.bb.cc:port它对我有用,非常感谢!

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

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

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

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 "

The error occurs because of the configuration set-up in .npmrc file in the directory C://Users/<username>/ .

Open the .npmrc file in notepad and remove the proxy set up in there. You only need ms build version and ssl set to false as shown in这个截图.

This will solve the issue. And now the npm install will work perfectly fine.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM