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 search
:
npm info it worked if it ends with ok
npm verb cli [ 'node', '/usr/local/bin/npm', 'search' ]
npm info using [email protected]
npm info using [email protected]
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?
Update
I have created an issue on the NPM project to report this: https://github.com/isaacs/npm/issues/2866
I had the same issue and finally it was resolved by disconnecting from all VPN .
For those using Jenkins or other CI server: it matters where you define your proxies, especially when they're different in your local development environment and the CI environment. In this case:
403 Forbidden
with little hint to the fact that you're using the wrong proxy. Check your gradle.properties
or such and fix/override as necessary.TLDR: define proxies not in the project but on the machine you're working on.
Due to security violations, organizations may have their own repositories.
set your local repo as below.
npm config set registry https://yourorg-artifactory.com/
I hope this will solve the issue.
If you need to provide a username and password to authenticate at your proxy, this is the syntax to use:
npm config set proxy http://usr:pwd@host:port
npm config set https-proxy http://usr:pwd@host:port
On windows 10, do
npm config edit
This will open config file in a text editor. Delete all the set proxy variables by user and only let default values stay.
;;;;
; npm userconfig file
; this is a simple ini-formatted file
; lines that start with semi-colons are comments.
; read `npm help config` for help on the various options
;;;;
--->Delete everything proxy settings from here.
;;;;
; all options with default values
;;;;
Close and save. Try again. That's what worked for me in my localhost.
If anyone else ends up breaking their proxy config settings go to your .npmrc, to type in the settings. This file is located at your node root folder level.
Here's whats my corrected file looks like:
#proxy = http://proxy.company.com:8080
https-proxy = https://proxy.company.com:8080
registry = http://registry.npmjs.org/
In my case, I read the registry that npm using:
npm config get registry
and I got
http://registry.npmjs.org/
then I had just changed http
to https
like this:
npm config set registry https://registry.npmjs.org/
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.
Source: Stackoverflow.com