407 Authentication required npm

2020-07-09 02:41发布

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?

4条回答
贼婆χ
2楼-- · 2020-07-09 02:59

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).

查看更多
别忘想泡老子
3楼-- · 2020-07-09 03:02

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
查看更多
家丑人穷心不美
4楼-- · 2020-07-09 03:06

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!

查看更多
兄弟一词,经得起流年.
5楼-- · 2020-07-09 03:23

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

查看更多
登录 后发表回答