19

Hello everyone I´ve been trying to configure and use npm on my enterprise PC without success.

I´ve set proxy, https-proxy, strict-ssl false, registry http://registry.npmjs.org proxy has been set like this "http://user:password@proxy_ip:proxy:port" Where the password has a special character written in urlencode.

npm config get proxy 

returns proxy with credentials as they should be.

I have cleared my npm cache and tried again.

No success.

Any ideas what can be the problem?

AndiFB
  • 239
  • 1
  • 2
  • 12

9 Answers9

19

I recommend reading through this article to configure the proxy for npm. http://wil.boayue.com/blog/2013/06/14/using-npm-behind-a-proxy/

  • npm config set proxy http://proxy.company.com:proxyport

  • npm config set http-proxy http://proxy.company.com:proxyport

  • npm config set https-proxy http://proxy.company.com:proxyport

Hope this is useful for you!

Suhas Gavad
  • 1,199
  • 1
  • 8
  • 12
  • Thank you Suhas i have already found the solution as lautit said the domain was left in my proxy configuration. I have read quite a lot before asking but couldn´t fix the problem – AndiFB Apr 18 '18 at 19:30
  • use encodeURIComponent to generate encoded password. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent and output of encodeURIComponent stuff into http://username:encodedpass@proxy.com – Sameer Amrutia May 27 '21 at 14:35
  • Using npm 9.7.2: "http-proxy is not a valid npm option" The other two options work as expected. – Attila Csipak Jun 28 '23 at 14:37
15

Usually, when you are behind a corporate proxy, it is needed to add the domain where you are at. Given that also the characters should be URL encoded, it would look like:

https://domain%5Cusername:password@proxy:port

lautit
  • 166
  • 1
  • 3
  • 1
    what is mean by domain here? can u clarify. – Mohan Jul 26 '20 at 08:23
  • 1
    I think he means Active Directory Domain – ama Nov 25 '20 at 15:41
  • use encodeURIComponent to generate encoded password. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent and output of encodeURIComponent stuff into http://username:encodedpass@proxy.com – Sameer Amrutia May 27 '21 at 14:38
15

We should add proxy with username and password to avoid this error. For example:

  • username: admin
  • password: admin123
  • proxy: 172.10.3.21
  • port: 3128

npm config set proxy http://admin:admin123@172.10.3.21:3128
npm config set https-proxy http://admin:admin123@172.10.3.21:3128
Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
Deepa
  • 850
  • 1
  • 10
  • 11
  • 3
    Is there no way to do this than to expose password like this? I was hoping on Windows machine 'Credential manager' would work, but it does not! – Siva Mar 02 '20 at 13:06
8

Editing the .npmrc file in user folder worked for me. I set the proxy and npm registry as follows:

proxy=http://username:password@proxy:port/
https-proxy=http://username:password@proxy:port
registry=http://registry.npmjs.org/  

Note : for usenames and passwords containing special charcters, the characters need to be encoded in the proxy configuration. e.g if username is "user" and password is "1234@user", then the .npmrc file will look like :

proxy=http://user:1234%40user@proxy:port/
https-proxy=http://user:1234@user@proxy:port
registry=http://registry.npmjs.org/ 

where, %40 is the encoded form of "@". In my case, the pound symbol(#) was not getting accepted in username or password(Dont know why).

1

if you use windows and cntlm and you get a 407 error from cntlm proxy server, make sure that your PassNTLMv2 in the cntlm.ini is up-to-date, as you have to recreate it, everytime that you change domain password.

Andreas Panagiotidis
  • 2,763
  • 35
  • 32
1

As others mention above you should set both the proxy and https-proxy configuration variables. as below:

https-proxy=http://userName:password@urlOfYourProxy:8080/

What no mentions is that the https-proxy variable should point to a proxy url that uses the http protocol NOT the https protocol (as shown above)!! Pretty darned counter intuitive.

Squibly
  • 335
  • 2
  • 7
1

I had this error on my corporate machine and this command in Terminal fixed it:

proxyOn () {
    export PROXY_CREDS=http://localhost:9000
    export ALL_PROXY=${PROXY_CREDS}
    export https_proxy=${PROXY_CREDS}
    export http_proxy=${PROXY_CREDS}
    export HTTP_PROXY=${PROXY_CREDS}
    export HTTPS_PROXY=${PROXY_CREDS}
}
Matt Bearson
  • 993
  • 8
  • 15
0

The character dot . , dont work on http request but &#46 remplace it

  1. Before npm config set proxy http://name.surname:pwrd@host:port
  2. After npm config set proxy http://name&#46surname:pwrd@host:port
0

When I received that error it was because our security team changed the url of the proxy. Updating to the new url fixed it for me.

Joe
  • 49
  • 6
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34472356) – OBrien Evance Jun 01 '23 at 06:31