npm5 does not accept proxy settings - node.js

I upgraded to latest npm 5 today and it started throwing me following error.
npm ERR! code E407
npm ERR! 407 Proxy Authorization Required: <node-module>
I have proxy setting configured in .npmrc file. Does NPM 5 maintain any other file for proxy setting?

I too was facing the same issue but I believe my issue was due to NTLM authentication as I was on windows (sigh!).
If you too are on windows, follow these steps:
Install fiddler
Open Fiddler -> Rules -> Automatically Authenticate
Change proxy and https-proxy of npm to "http://localhost:8888"
try running npm install now.
Note: You may need to change proxy settings of Git too.

I could fix it by deleting npm folder from AppData/
And then ran
npm cache clean
and reinstalled npm using
npm i -g npm#latest

Related

npm ERR! code ECONNRESET when doing create-react-app

I'm at my wits' end as I keep hitting this error when I'm trying to create-react-app. I am not using any proxies (like company proxy etc), as this is on my personal desktop.
When I check the logs, there is nothing.
I have tried the following solutions:
tried using npm config set registry http://registry.npmjs.org/ (have also tried going to this site on the browser, and I am indeed able to access it)
tried the following commands to remove proxy:npm config rm proxy, npm config rm https-proxy, npm config delete proxy, npm config delete http-proxy, npm config delete https-proxy
tried npm uninstall -g create-react-app to update it
tried npm cache clean --force
installed yarn and used its create-react-app
Uninstalled Node and reinstalled Node
Updated to the latest version of npm
Launched the command prompt in admin mode
Disabled the "Automatically Detect Settings" in the Windows Proxy settings
Any help greatly appreciated!

npm ERR! code ERR_SOCKET_TIMEOUT npm ERR! network Socket timeout

This the error:
npm ERR! code ERR_SOCKET_TIMEOUT
npm ERR! network Socket timeout
npm ERR! network This is a problem 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'
I have running: -npm cache clean --force
Deleted node_modules and lock-package.json and run npm install but still got me that error
Try this answer
or run npm i -g npm#8.5.1
i think it's an issue with npm version , 8.5.1 solves the problem in most cases
basically try earlier versions and i think the problem will be solved
I faced this error some days ago. I changed the timeout and it works for me. (Note: my npm version is 8.19.1)
You can try this solution with other npm versions as well.
First of all, check the current settings. For checking the current settings run npm config ls -l or grep fetch
Then, check these 4 values (fetch-retries, fetch-retry-factor, fetch-retry-maxtimeout, fetch-retry-mintimeout, fetch-timeout)
$ npm config ls -l | grep fetch
fetch-retries = 2
fetch-retry-factor = 10
fetch-retry-maxtimeout = 60000
fetch-retry-mintimeout = 10000
fetch-timeout = 300000
For changing the time out, Run these two commands-
npm config set fetch-retry-mintimeout 20000
npm config set fetch-retry-maxtimeout 120000
I faced this problem recently. I tried many solutions like npm cache verify, npm cache clean --force, npm config set fetch-retry-mintimeout, npm config set fetch-retry-maxtimeout, deleting package-lock.json, using different version of npm and/or node.
But the solution that worked for me was to switch to yarn.
I solved this by setting a timeout of 60000 for npm in the .npmrc file. To do that from your terminal, simply do the following:
$ nano .npmrc from your work directory if you want a configuration locally.
Add timeout=60000, save and you're good to go.
Originally posted here: https://github.com/facebook/create-react-app/issues/10251
You can resolve this using YARN package manager. yarn create react-app my-app
hope it help.
I am not sure if this will help anyone else, but what appears to have worked for me was dropping my company's VPN connection and reestablishing it!
In my scenario, it was the yarn.lock file availability. So the installer tried to fetch dependencies and threw an error since the response time was delayed. So deleted both yarn.lock and package.lock file and reinstalled after setting npm to npm#8.5.1
I found solution for it, which works great for me
1.npm config set registry http://registry.npmjs.org/
2.npm i or npm i --save --legacy-peer-deps
Try removing proxy settings by running the commands below:
$ npm config rm proxy
$ npm config rm https-proxy
mine worked using these steps, hope it works for you too.
npm cache clean --force
npm uninstall -g create-react-app
npm uninstall create-react-app
and then
npx create-react-app project-app
if it does not then probably your internet connection is poor or there is a proxy set up error. let me know if it does not work.

how to fix connect ENETUNREACH on npm on linux

i am not using a proxy im just a noob trying to learn how to develop with create-react-app locally on my machine(linux)
this is the output of tracepath registry.npmjs.org
1?: [LOCALHOST] 0.020ms pmtu 1500
1: 2001:4451:664:1400:caf6:c8ff:fef2:bdcb 2.906ms !N
1: 2001:4451:664:1400:caf6:c8ff:fef2:bdcb 0.995ms !N
Resume: pmtu 1500
i think this proves im not using a proxy.
but i keep getting this error
npm ERR! code ENETUNREACH
npm ERR! syscall connect
npm ERR! errno ENETUNREACH
for anything npm. i dont know what to do.
i have tried..
deleting the package.json in my home directory. deleting the
package-lock.json in my home directory. deleting the .npm directory
in my home direcory.
clearing the cache with the npm config command
setting https-proxy from the config to null setting proxy from the
config to null setting the registry to https://registry.npmjs.org
setting the registry to htpp://registry.npmjs.org uninstalled npm
and dependencies then reinstalled unintsalled npm and dependencies then installed nvm and reinstalled node through that
npm install --verbose doesnt say any error messages
please somebody help me, i try just about anything shy of reinstalling my os.
The issue is that node 18 (not happening on 16) is trying to resolve by ipv6 first.
Can override it by exporting the environment variable:
NODE_OPTIONS = "--dns-result-order=ipv4first"

How do I remove corporate proxy? I have tried everything, nothing works

I have an artifactory preventing me from setting up any new apps or libraries. When I had access to corporate VPN, I could bypass it.
I am basically getting this when trying any npm install:
npm ERR!
403 Forbidden - GET https:// (artifactory link)
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy, or
npm ERR! 403 on a server you do not have access to.
I have tried this:
npm config rm proxy
npm config rm https-proxy
I have even reinstalled Git and Node. Nothing works. Please help!
Try to set noproxy
https://docs.npmjs.com/cli/v8/using-npm/config#noproxy
npm config set noproxy "my-proxy-host"
You can set your npm registry to the default registry
use the following command:
npm config set registry https://registry.npmjs.org/

receiving error: 'Error: SSL Error: SELF_SIGNED_CERT_IN_CHAIN' while using npm

I am using npm v1.0.104/node 0.6.12 on ubuntu - I am receiving the error copied below while attempting to install any new modules via npm (I tested socket.io earlier using http, not https though & am wondering if that could have resulted in the issue with npm/unsigned certs). The error pops up once npm tries to resolve the 'https://registry.npmjs.org' URL. Is there anyway I can ignore the error or perhaps locate/add the cert to a trusted store in order to continue using npm.
Any insight on what needs to be done to resolve the issue will be appreciated (I would prefer to resolve the issue through configuration as opposed to re-installing if possible).
Error: "Error: SSL Error: SELF_SIGNED_CERT_IN_CHAIN"
Full Message:
npm ERR! Error: SSL Error: SELF_SIGNED_CERT_IN_CHAIN
npm ERR! at ClientRequest.<anonymous> (/usr/lib/node_modules/npm/node_modules/request/main.js:252:28)
npm ERR! at ClientRequest.emit (events.js:67:17)
npm ERR! at HTTPParser.onIncoming (http.js:1261:11)
npm ERR! at HTTPParser.onHeadersComplete (http.js:102:31)
npm ERR! at CleartextStream.ondata (http.js:1150:24)
npm ERR! at CleartextStream._push (tls.js:375:27)
npm ERR! at SecurePair.cycle (tls.js:734:20)
npm ERR! at EncryptedStream.write (tls.js:130:13)
npm ERR! at Socket.ondata (stream.js:38:26)
npm ERR! at Socket.emit (events.js:67:17)
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR!
npm ERR! System Linux 2.6.38-13-generic
npm ERR! command "node" "/usr/bin/npm" "install" "jed"
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.0.104
Running the following helped resolve the issue:
npm config set strict-ssl false
I cannot comment on whether it will cause any other issues at this point in time.
As of February 27, 2014, npm no longer supports its self-signed certificates. The following options, as recommended by npm, is to do one of the following:
Upgrade your version of npm
npm install npm -g --ca=""
-- OR --
Tell your current version of npm to use known registrars
npm config set ca ""
Update: npm has posted More help with SELF_SIGNED_CERT_IN_CHAIN and npm with more solutions particular to different environments
You may or may not need to prepend sudo to the recommendations.
Other options
It seems that people are having issues using npm's recommendations, so here are some other potential solutions.
Upgrade Node itself
Receiving this error may suggest you have an older version of node, which naturally comes with an older version of npm. One solution is to upgrade your version of Node. This is likely the best option as it brings you up to date and fixes existing bugs and vulnerabilities.
The process here depends on how you've installed Node, your operating system, and otherwise.
Update npm
Being that you probably got here while trying to install a package, it is possible that npm install npm -g might fail with the same error. If this is the case, use update instead. As suggested by Nisanth Sojan:
npm update npm -g
Update npm alternative
One way around the underlying issue is to use known registrars, install, and then stop using known registrars. As suggested by jnylen:
npm config set ca ""
npm install npm -g
npm config delete ca
For now I just switched registry URL from https to http. Like this:
npm config set registry="http://registry.npmjs.org/"
npm config set strict-ssl false -g
To save it globally
The error SELF_SIGNED_CERT_IN_CHAIN means that you have self signed certificate in certificate chain which is basically not trusted by the system.
If that happens, basically something fishy is going on, therefore as people already commented, it is not recommended to just disable certificate checks, but better approach is to understand what is the problem and fix the cause of it.
This maybe related either to:
custom repository address which doesn't have the right certificate,
a corporate network with transparent proxy.
If you're behind a corporate web proxy, you should set-up the proper HTTP_PROXY/HTTPS_PROXY environment variables or set them via npm:
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
See: How to setup Node.js and Npm behind a corporate web proxy
If you trust the host, you can export the self-signed certificate from the chain and import them into system, so they're marked as trusted.
This can be achieved by checking the certificates by (change example.com into npm repo which is failing based on the npm-debug.log):
openssl s_client -showcerts -connect example.com:443 < /dev/null
then save the certificate content (between BEGIN and END) into .crt file in order to import it.
Linux
As per suggestion, you can add the below to the /etc/environment file (Node 7.4+) to export your CA chain, like:
NODE_EXTRA_CA_CERTS=/etc/pki/ca-trust/source/anchors/yourCer‌​ts.pem
CentOS
On CentOS 5 this can be appended into /etc/pki/tls/certs/ca-bundle.crt file, e.g.
ex +'g/BEGIN CERTIFICATE/,/END CERTIFICATE/p' <(echo | openssl s_client -showcerts -connect example.com:443) -scq | sudo tee -a /etc/pki/tls/certs/ca-bundle.crt
sudo update-ca-trust force-enable
sudo update-ca-trust extract
npm install
Note: To export only first certificate, remove g at the beginning.
In CentOS 6, the certificate file can be copied to /etc/pki/ca-trust/source/anchors/.
Ubuntu/Debian
In Ubuntu/Debian, copy CRT file into /usr/local/share/ca-certificates/ then run:
sudo update-ca-certificates
macOS
In macOS you can run:
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/foo.crt
Windows
In Windows: certutil -addstore -f "ROOT" new-root-certificate.crt
See also: npm - Troubleshooting - SSL Error
You need to upgrade npm.
// Do this first, or the upgrade will fail
npm config set ca ""
npm install npm -g
// Undo the previous config change
npm config delete ca
You may need to prefix those commands with sudo.
Source: http://blog.npmjs.org/post/78085451721/npms-self-signed-certificate-is-no-more
Putting this before the command seems to work NODE_TLS_REJECT_UNAUTHORIZED=0.
ex: NODE_TLS_REJECT_UNAUTHORIZED=0 npm ...
It would be best to figure out how to make node see self signed certificate as valid. strict-ssl suggestion above didn't work for me for some reason. If you understand the security implications and need a temporary quick fix, this is what I found in some random github issues during Google search of the error.
The repository no longer supports self-signed certificates. You need to upgrade npm.
// Disable the certificate temporarily in order to do the upgrade
npm config set ca ""
// Upgrade npm. -g (global) means you need root permissions; be root
// or prepend `sudo`
sudo npm install npm -g
// Undo the previous config change
npm config delete ca
// For Ubuntu/Debian-sid/Mint, node package is renamed to nodejs which
// npm cannot find. Fix this:
sudo ln -s /usr/bin/nodejs /usr/bin/node
You need to open a new terminal session in order to use the updated npm.
Source: This was originally an edit on jnylen's answer. Although the guidelines say "We welcome all constructive edits, but please make them substantial," the edit was rejected due to "This edit changes too much in the original post; the original meaning or intent of the post would be lost." I guess the community prefers a separate answer.
For those who on a mac with the same issue and installed npm via homebrew:
brew uninstall npm
then
brew install npm
Works for me on osx (10.9.1)
EDIT: You may need to brew update before installing npm. You can also do a brew upgrade after updating homebrew. Also it might be helpful to run brew doctor if you run into any other issues.
just for development in windows
$Env:NODE_TLS_REJECT_UNAUTHORIZED=0
Quick and clean solution (linux tested) (After fatidic February 27, 2014)
Uninstall npm
npm rm npm -g
Install npm (new URL is www.npmjs.org instead npmjs.org)
curl https://www.npmjs.org/install.sh | sh
Tip: how to install node.js in linux https://stackoverflow.com/a/22099363/333061
I've created an article how to disable most npm problems behind a corporate firewall if you're out of options.
Be aware that you might be vulnerable to attacks.
https://wnderlvst.com/stories/102a237a-cea1-463b-89db-82224f1c1cbe
Powershell
yarn config set "strict-ssl" false
yarn config set "network-timeout" 600000
$env:NODE_TLS_REJECT_UNAUTHORIZED=0
Uninstall NPM and install it again.
As of February 27, 2014 npm no longer supports its self-signed certificates.
http://blog.npmjs.org/post/78085451721/npms-self-signed-certificate-is-no-more
The link above suggests upgrading NPM using NPM. This also fails with SELF_SIGNED_CERT_IN_CHAIN...
Turning off SSL seems like a profoundly bad idea. npm's blog explains that they no longer support their self-signed cert. They suggest upgrading npm via npm install npm -g, but I of course got the same SELF_SIGNED_CERT_IN_CHAIN error. So I just updated node, which updated npm along with it. Exact procedure depends on how you installed node in the first place.
You will need to find the proxy details of your company and the npm registry that you should be using.
After that you can specify the same in .npmrc file located under user folder C:/users/<your_user>.
this is how it can be specified -
registry=https://your_company/npm/registry/
proxy=http://username:password#proxy:port/
https-proxy=http://username:password#proxy:port/
The password is in plain text which is obviously not ideal may be there is a way to encrypt it in a way that npm understands.
For me this was a super simple solution. All I needed to do was set the https-proxy in npm via npm config set https-proxy "http://proxyserverurl:port". #somshivam 's solution works too, but if you're going to have the module installed by a cloud pipeline like Azure DevOps, you can't have the proxy setting in the npmrc file or it will fail.
I was having the same SSL self signed cert error because of corporate proxy. I was having issue while installing node-gyp. I tried uninstalling Angular/cli first and installing node-gyp and then try reinstalling Angular cli
npm uninstall -g #angular/cli
npm install -g node-gyp
npm install -g #angular/cli
It worked perfectly

Resources