I'm trying to run npm behind a proxy. I've tried both entering the proxy directly or through Authoxy:
npm config set proxy http://localhost:8999 npm config set https-proxy http://localhost:8999
Regardless of which proxy I use, I always end up with the same error when running
npm info it worked if it ends with ok npm verb cli [ 'node', '/usr/local/bin/npm', 'search' ] npm info using firstname.lastname@example.org npm info using email@example.com npm verb config file /Users/xxx/.npmrc npm verb config file /usr/local/etc/npmrc npm verb config file /usr/local/lib/node_modules/npm/npmrc npm WARN Building the local index for the first time, please be patient npm verb url raw /-/all npm verb url resolving [ 'https://registry.npmjs.org/', './-/all' ] npm verb url resolved https://registry.npmjs.org/-/all npm info retry registry request attempt 1 at 09:48:47 npm http GET https://registry.npmjs.org/-/all npm info retry will retry, error on last attempt: Error: tunneling socket could not be established, sutatusCode=403 npm info retry registry request attempt 2 at 09:48:57 npm http GET https://registry.npmjs.org/-/all npm info retry will retry, error on last attempt: Error: tunneling socket could not be established, sutatusCode=403 npm info retry registry request attempt 3 at 09:49:57 npm http GET https://registry.npmjs.org/-/all npm ERR! Error: tunneling socket could not be established, sutatusCode=403 npm ERR! at ClientRequest.onConnect (/usr/local/lib/node_modules/npm/node_modules/request/tunnel.js:148:19) npm ERR! at ClientRequest.g (events.js:185:14) npm ERR! at ClientRequest.EventEmitter.emit (events.js:115:20) npm ERR! at Socket.socketOnData (http.js:1383:11) npm ERR! at TCP.onread (net.js:410:27)
The command always fails with
sutatusCode [sic!] 403 - which means unauthorized. I have set up Authoxy to not require a username/password. The same error happens when I bypass Authoxy and provide the real proxy credentials for our NTLM proxy in the form of http:// user:pass@proxy:port.
How can I make this work through the proxy?
I have created an issue on the NPM project to report this: https://github.com/isaacs/npm/issues/2866
OK, so within minutes after posting the question, I found the answer myself here: https://github.com/npm/npm/issues/2119#issuecomment-5321857
The issue seems to be that npm is not that great with HTTPS over a proxy. Changing the registry URL from HTTPS to HTTP fixed it for me:
npm config set registry http://registry.npmjs.org/
I still have to provide the proxy config (through Authoxy in my case), but everything works fine now.
Seems to be a common issue, but not well documented. I hope this answer here will make it easier for people to find if they run into this issue.
npm config set proxy http://proxy.company.com:8080 npm config set https-proxy http://proxy.company.com:8080
credit goes to http://jjasonclark.com/how-to-setup-node-behind-web-proxy.