264

I'm having a problem with npm, I cant install anything. Here is the error messages:

C:\Windows\system32>npm install -g yo
npm http GET https://registry.npmjs.org/yo
npm http GET https://registry.npmjs.org/yo
npm http GET https://registry.npmjs.org/yo
npm ERR! network read ECONNRESET
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settin
gs.
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'

npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "yo"
npm ERR! cwd C:\Windows\system32
npm ERR! node -v v0.10.17
npm ERR! npm -v 1.3.8
npm ERR! syscall read
npm ERR! code ECONNRESET
npm ERR! errno ECONNRESET
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\Windows\system32\npm-debug.log
npm ERR! not ok code 0

Any idea why is this? Here are my network settings and it seems I dont have any proxy configured. I also disabled all the firewalls.

enter image description here

5
  • Are you able to visit this page in a browser registry.npmjs.org/yo? Commented Aug 24, 2013 at 13:47
  • It appears their SSL certificate expired! Commented Aug 24, 2013 at 20:16
  • @thefourtheye Yes I can visit that link
    – Omar
    Commented Aug 25, 2013 at 7:38
  • npm doesnt install anything. This problem isnt exclusive in installing express
    – Omar
    Commented Aug 25, 2013 at 8:21
  • You may need to check C:\Windows\system32\npm-debug.log, this file will have more accurate information to resolve your problem. Commented Aug 18, 2017 at 5:39

36 Answers 36

461

use

npm config set registry http://registry.npmjs.org/

so that npm requests for http url instead of https.

and then try the same npm install command

7
  • 28
    can you please also provide some explanation , it will be very helpful. Commented Nov 26, 2014 at 5:13
  • 55
    This "fix" is susceptible to man-in-the-middle attacks. I wouldn't use this for production.
    – thesmart
    Commented Apr 27, 2016 at 20:48
  • 5
    The problem could easily be you are being blocked to that website by your ISP's or Company's firewall/proxy. Using the above method is quicker and easier but it's also insecure as it doesnt verify you are connected to the right website. To check if you are being blocked simply go to registry.npmjs.org in your browser. You should get some text back.
    – Marlon
    Commented Aug 31, 2016 at 17:54
  • 2
    haha....I'd been trying to get past this off and on for months. I had been just disabling VPN, grabbing packages, then logging back on. Thanks for this. All others, issue is simply your proxy address/port is wrong or (in this case) your proxy is not configured to listen for HTTPS traffic.
    – voidzero
    Commented Sep 13, 2016 at 16:16
  • 4
    I know it may not be secure but come on - I TRIED EVERYTHING to get rid of ECONNRESET error while creating new angular 4 app via Angular CLI and that solution only worked. After creating new project you can switch back to https. Anyway @mithunsatheesh thank you once again.
    – born2fr4g
    Commented Jul 22, 2017 at 11:59
89

You may want to check your NPM proxy settings and perhaps remove it.

npm config get proxy
npm config rm proxy
npm config rm https-proxy

One might expect a fresh install of NodeJS+NPM would not have a proxy configured. Strangely enough, mine did come with a proxy defined, pointing to an IP and port 3128. Removing the proxy did the trick.

4
  • 2
    I was trying to install jquery in Angular project using the cmd - npm install jquery But there was a proxy error which is now resolved when tried this solution. Commented Jan 26, 2019 at 6:53
  • After a day, I have solved my problem npm ERR! network In most cases you are behind a proxy or have bad network settings with this solution. Thanks Commented Nov 30, 2020 at 15:00
  • This actually worked, and it seems to be more secure than the other solution.
    – Kamil B
    Commented Jan 9, 2021 at 19:24
  • This worked for me also. Unfortunately the earlier solution not worked. Commented Jul 1, 2022 at 10:04
22

Remove your proxy settings at home and switch on at Office networks, This may be irritating, But It worked for me:

npm config set proxy http://xxx.xxx.xxx.4:8080   
npm config set https-proxy http://xxx.xxx.xxx.4:8080

and

npm config rm proxy   
npm config rm https-proxy
2
  • The last bit worked for me - I checked my .npmrc file and the old https proxy was still there after removing the proxy
    – Jayx
    Commented Mar 17, 2016 at 12:42
  • this is working but how to unconfigure or reconfigure to default, whenever go to other network with out proxy??
    – D V Yogesh
    Commented Nov 23, 2017 at 7:46
18

You may also need to specify the proxy server/port, in some environments the system settings for proxy are not enough for npm to work.

    npm config set proxy "http://your-proxy.com:80"
0
15

This can be caused by installing anything with npm using sudo -- this causes the files in the cache to be owned by root, resulting in this problem. You can fix it by running:

sudo rm -rf ~/.npm

to remove the cache. Then try whatever you were doing again, making sure you never use sudo along with npm (or the problem may come back).

Lots more information: npm throws error without sudo

4
  • forgot about needing to elevate to Administrator to perform npm -g update (as I did to install it). Thanks.
    – George
    Commented Nov 1, 2015 at 1:43
  • 10
    How does this cause ECONNRESET, exactly? You're right that sudo can break things in novel ways, but causing the registry server to drop connection is a bit unbelievable.
    – Mattie
    Commented Apr 29, 2016 at 13:19
  • This worked for me! I was trying to do npm i next-pwa and got similar error as mentioned in the question. Didn't have a proxy set so other solutions didn't work for me. I remembered having used sudo and npm commands together previously so tried this solution and hopefully it worked as well. Loads of thanks @Kevin! Commented Jun 29, 2022 at 16:33
  • Using npm as a non-root user worked for me but I did not need to remove the .npm folder. I also used the chown command to remove the root ownership of some folders.
    – baptx
    Commented May 5 at 16:40
13

Restarting my PC made it work.

4
  • So true, tried all the other solutions, this worked. But in my case, I also ran the sudo apt update -> sudo apt upgrade before deleting my node_modules folder and tried installing again only to encounter this error. Restart fixed it for me. Commented Apr 1, 2022 at 5:57
  • Solution that legends doo Commented Aug 26, 2022 at 23:20
  • A few days ago, I got this issue and did not even need to restart the computer. Retrying the installation fixed the issue (I modified an installation script in order to resume installation instead of starting from scratch).
    – baptx
    Commented May 6 at 16:29
  • It's funny how the simplest solutions fix the biggest problems. worked for me as well (after trying all of the above .... )
    – matmiz
    Commented Sep 9 at 8:22
8

Remove yarn.lock , package-lock.json, node_modules

and then

npm install -f 

Worked for me

5

I've tried almost all methods posted here and in other pages but didn't work. Here are the commands I've executed in order, which I encourage you to try because it worked for many people (but not me):

  • npm config rm proxy
  • npm config rm https-proxy
  • npm config set https-proxy https://username:[email protected]:6050
  • npm config set proxy http://username:[email protected]:6050
  • npm config set registry http://registry.npmjs.org/

And then trying to install the package npm install -g express, but it failed.

However, when I tried to run npm install npm@latest -g it miraculously executed and installed fine!
Then running npm install -g express again worked perfectly fine too.

TL;DR: updating npm to the latest version solved the issue (currently 6.0.1)

4

The three thing to make npm working well inside the proxy network .

This set npm registry , By default it may take https.

npm config set registry "http://registry.npmjs.org/"

Second is two set proxy in your system . If your organization use proxy or you.

npm config set proxy "http://username:password@proxy-url:proxy-port"

npm config set https-proxy "http://username:password@proxy-url:proxy-port"

You can also check if they are set or not , by

npm config get https-proxy

for all values.

2
  • It does not show me any error, but installation is stuck at line - loadRequestedDeps: sill install loadAllDepsIntoIdealTree
    – RSB
    Commented Feb 1, 2018 at 12:17
  • This is another issue . The proxy issue of your is solved . May this short your thing stackoverflow.com/questions/40874237/… Commented Feb 1, 2018 at 13:05
4

npm config rm proxy

npm config rm https-proxy

works for me!

0
4

I had the same issue in windows while installing any package from npm. Fixed that with - ** open command prompt as administrator and run these 3 commands **/

1. npm config rm proxy

2. npm config rm https-proxy

3. npm install npm@latest -g

FOR MAC / LINUX
1. sudo npm config rm proxy

2. sudo npm config rm https-proxy

3. sudo npm install npm@latest -g

Basically this was version isuue with npm . Please check its worrking

3

I had the same issue but none of these solutions worked correctly. Finally, I have installed packages via yarn, which is npm-compatible. As per official website:

Migrating from npm should be a fairly easy process for most users. Yarn can consume the same package.json format as npm, and can install any package from the npm registry.

Just install the yarn and then then, run the install by using the following command, the equivalent to npm install in yarn:

yarn install

Read more at – Yarn: Migrating from npm.

1
  • yarn is managing issues with the network - retrying, instead of aborting like npm Commented Jan 15 at 5:18
2

This is an old question, but anyway.

I had this issue, when I was trying to deploy to heroku, and the fix that worked for me was to update the npm version that was used. I had version 2.x.x and I updated to 3.x.x

1
  • Or specify an npm version compatible with the node engine being used.
    – bknights
    Commented Jan 19, 2023 at 2:13
2

If you're using Windows you should follow up on Advanced System Settings to check the env vars declared over there, you should notice that the proxy configuration may lie within environment variables, like in the picture below:

Windows env vars

So if your proxy server is not available or is blocking traffic from npm you might notice the aforementioned error in this topic. Maybe you don't need any proxy at all, in this case, just remove this HTTP_PROXY env variables.

I had turned all proxy configurations off in my Windows and npm settings, however, npm was still getting timeout and connection errors while downloading resources, then I figured out there was still a proxy configuration left on env variables, which was causing all the trouble.

1

At work, i had to load up my browser and browse a webpage (which authenticates me to our web-filter). Then I retried the command and it worked successfully.

1
  • 3
    Not 100% sure if this is what helped me, or just a coincidence, but navigating to registry.npmjs.org in Firefox somehow helped npm install work the next time. I don't have any kind of web filter software.
    – TalkLittle
    Commented Aug 19, 2015 at 21:33
1

You may also encounter this error if you have a saved bearer token that is now invalid. I've encountered this when using a private repo where the accounts were wiped and reset, invalidating the tokens. Although your repo may not require authentication, if you have a token from a previous login it will be passed and if it's invalid your connection will be closed.

You can resolve this by either logging in again with the new user name and password, or presumably by simply logging out via npm.

1

I did not want to switch to http for the registry, what worked for me was downgrading from the latest Node version to the LTS version (as of now, 6.x).

1

I had the problem with npm throwing this error.

So basically whenever error was thrown i either used manual install
from git or waited and installed specified version like:

npm install resolve@^1.1.6

when running alone:

npm install resolve

didn't worked.

I updated node.js from 7 to 8 and npm install goes smoothly.

I think that maybe the version 7 caused this problem since @luschn downgraded to 6 so he didn't use 7 too.

Maybe the registry itself is returning errors without showing problems on their status pages because after some time i could install this one breaking package and then proceed with npm install to install the rest.

1

I had the same problem on my local home network without proxy. Other answers in this thread didn't work for me. What I ended up doing was using yarn which can be used interchangeably with npm:

yarn add

To this day I don't know why my npm still don't work. I know for sure that it's a problem with my Wi-Fi, because when I connect to LTE internet broadcasted from my smartphone npm install works again. It has probably something to do with router settings (problems started when I upgraded my internet speed and ISP worker replaced my old router with a new one).

1

I had the same problem when trying to run npm on system emulated in Oracle VirtualBox. I resolved it by adding Google DNS address in Network Adapter properties.

Network Adapter properties > IPv4 properties > Preferred DNS address: 8.8.8.8.

1

This is what worked for me:

proxy = http://1.1.1.1:3128/
https_proxy = http://1.1.1.1:3128/
strict-ssl = false
ca = null
registry = http://registry.npmjs.org/

Answer found here: https://fak3r.com/2015/07/31/howto-use-npm-behind-a-corporate-proxy/

1

Our company firewall will stop installing node hence connect to the personal network and install, it worked for me.

1

I found "npm config edit" to be more useful to update the entries for https-proxy, proxy, registry

I did something like this

  • npm config list
  • npm config edit (opens in vi)
  • Edit or set the config entries for https-proxy, proxy, registry
  • npm install
1

Just in case...simply trying one more time worked for me. It could just be a temporary connection issue.

1

I found a simple solution for this. if you are using windows 10 then go to the network setting and turn off the automatic proxy detection.it solved my problem. I was looking for this for the last 2 days.

1

In my case changing wifi works for me. I usually work in my living room. But I changed to my room just a few days ago. The wifi did not reach the 2nd floor so we used Wifi Extender.

Then I had this issue. I tried switching back to my living room's wifi and I got no problem from doing the same command.

2
  • 1
    Thank you for sharing this - same problem and same solution!! Commented Feb 21, 2023 at 19:35
  • Haha glad it helped @RichardFoss apparently it's a network issue as the error implied I guess ECONNRESET, connection reset stuff. Commented Feb 23, 2023 at 6:41
1

In my case, I was running a Node JS application in another CMD, and that application was listening to port 8088.

So when I was executing any command related to npm it was throwing the above error.

The solution in my case was: Stopping ANY Running Node JS applications and retrying to execute the npm command again. the installation should be completed successfully, without any errors.

1

If you live in China, try the below command, it's the npm mirror registry, and supports https:

npm config set registry https://registry.npmmirror.com/

0
0

npm config set https-proxy "http://username:password@proxy-url:proxy-port" worked for me

0

In case this helps anyone who was in my situation: I recently installed Fiddler, which (unbeknownst to me) added a network proxy through 127.0.0.1:8866. I went into my Ubuntu network settings, clicked into the "Network Proxy" settings, and disabled it, and then all was back to normal.

So in general, check to make sure you haven't got a network proxy set up due to a side-effect of something else you were doing.

Not the answer you're looking for? Browse other questions tagged or ask your own question.