238

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

Omar
  • 7,835
  • 14
  • 62
  • 108

32 Answers32

435

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

Mithun Satheesh
  • 27,240
  • 14
  • 77
  • 101
  • 26
    can you please also provide some explanation , it will be very helpful. – Rishul Matta Nov 26 '14 at 05:13
  • 46
    This "fix" is susceptible to man-in-the-middle attacks. I wouldn't use this for production. – thesmart Apr 27 '16 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 https://registry.npmjs.org/ in your browser. You should get some text back. – Marlon Aug 31 '16 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 Sep 13 '16 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 Jul 22 '17 at 11:59
  • Right now configuring npm to use http instead of https doesn't resolve the econnect error. Instead, it results in a different error: npm ERR! code ENOAUDIT npm ERR! audit Your configured registry (http://registry.npmjs.org/) may not support audit requests, or the audit endpoint may be temporarily unavailable. – Lazor Dec 08 '20 at 23:30
  • @Mithun Satheesh getting SocketException: OS Error: Connection timed out, errno = 110, address = 10.xxx.xx.xxx, port = 43xxx , with local host api, any solution i tried all these command of npm. – s.j Apr 07 '21 at 11:55
74

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.

jediz
  • 4,459
  • 5
  • 36
  • 41
21

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
Martin Zabel
  • 3,589
  • 3
  • 19
  • 34
Ignatius Andrew
  • 8,012
  • 3
  • 54
  • 54
  • The last bit worked for me - I checked my .npmrc file and the old https proxy was still there after removing the proxy – Jayx Mar 17 '16 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 Nov 23 '17 at 07: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"
Dmitri Mogilevski
  • 426
  • 1
  • 5
  • 7
13

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

Community
  • 1
  • 1
Kevin Cooper
  • 5,018
  • 4
  • 37
  • 51
  • forgot about needing to elevate to Administrator to perform `npm -g update` (as I did to install it). Thanks. – George Nov 01 '15 at 01:43
  • 9
    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 Apr 29 '16 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! – Dorji Tshering Jun 29 '22 at 16:33
8

Restarting my PC made it worked.

Gowtham
  • 408
  • 5
  • 16
  • 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. – Prince Agrawal Apr 01 '22 at 05:57
  • Solution that legends doo – Muhammad Ibrahim Aug 26 '22 at 23:20
6

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

and then

npm install -f 

Worked for me

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
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.

Himanshu sharma
  • 7,487
  • 4
  • 42
  • 75
  • It does not show me any error, but installation is stuck at line - loadRequestedDeps: sill install loadAllDepsIntoIdealTree – RSB Feb 01 '18 at 12:17
  • This is another issue . The proxy issue of your is solved . May this short your thing https://stackoverflow.com/questions/40874237/npm-install-hangs-on-loadrequesteddeps – Himanshu sharma Feb 01 '18 at 13:05
4

npm config rm proxy

npm config rm https-proxy

works for me!

Aditya
  • 2,380
  • 2
  • 14
  • 39
samivic
  • 1,216
  • 14
  • 13
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

Shivam Gupta
  • 533
  • 4
  • 9
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.

Dariusz Woźniak
  • 9,640
  • 6
  • 60
  • 73
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

Dimitris Karagiannis
  • 8,942
  • 8
  • 38
  • 63
2

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:password@proxy.company.com:6050
  • npm config set proxy http://username:password@proxy.company.com: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)

Nuhman
  • 1,172
  • 15
  • 22
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.

s_bighead
  • 1,014
  • 13
  • 24
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.

Post Impatica
  • 14,999
  • 9
  • 67
  • 78
  • 2
    Not 100% sure if this is what helped me, or just a coincidence, but navigating to https://registry.npmjs.org/ in Firefox somehow helped npm install work the next time. I don't have any kind of web filter software. – TalkLittle Aug 19 '15 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.

Carth
  • 2,303
  • 1
  • 17
  • 26
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).

andyrandy
  • 72,880
  • 8
  • 113
  • 130
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.

Mike
  • 465
  • 5
  • 14
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).

Celebes
  • 1,371
  • 1
  • 12
  • 21
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.

Karol Trybulec
  • 1,056
  • 1
  • 11
  • 17
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/

Allan
  • 96
  • 1
  • 3
1

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

sahi
  • 11
  • 1
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.

alexr101
  • 588
  • 5
  • 13
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.

Engr.Aftab Ufaq
  • 3,356
  • 3
  • 21
  • 47
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.

ASammour
  • 865
  • 9
  • 12
1

Try the below command, it's the npm mirror registry, and supports https:

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

Wenfang Du
  • 8,804
  • 9
  • 59
  • 90
0

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

Om Mishra
  • 65
  • 5
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.

joe
  • 3,752
  • 1
  • 32
  • 41
0

it solved for me by use this code : npm install -g yarn

yarn global add create-react-app

Zain Alabdeen
  • 479
  • 3
  • 7
0

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.

Irfandy Jip
  • 1,308
  • 1
  • 18
  • 36
-3

Solution 1:

MAC + LINUX

run this command with sudo

sudo npm install -g yo

Windows

run cmd as administrator and then run this command again

Solution 2:

run this command and then try

npm config set registry http://registry.npmjs.org/
Muhammad Numan
  • 23,222
  • 6
  • 63
  • 80