21

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 ran npm cache clean --force

Deleted node_modules and package-lock.json and run npm install but still got me that error

Rifky Niyas
  • 1,737
  • 10
  • 25
Ira
  • 231
  • 1
  • 2
  • 5

15 Answers15

26

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

mod7ex
  • 874
  • 9
  • 27
18

I faced this error some days ago. I changed the timeout and it works for me. (Note: my npm version was 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

Then, check these 4 values (fetch-retries, fetch-retry-factor, fetch-retry-maxtimeout, fetch-retry-mintimeout, fetch-timeout)

$ npm config ls -l

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

Suptohita
  • 345
  • 2
  • 8
5

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!

cptully
  • 615
  • 1
  • 9
  • 24
4

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

FOBABS
  • 151
  • 6
3

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.

Rivosoa
  • 61
  • 2
  • 4
3

You can resolve this using YARN package manager. yarn create react-app my-app hope it help.

2

Try removing proxy settings by running the commands below:

$ npm config rm proxy
$ npm config rm https-proxy
David Njuguna
  • 803
  • 7
  • 8
1

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

Indunil Withana
  • 176
  • 1
  • 8
1

I was able to install packages using yarn install instead.

Luc Thi
  • 21
  • 1
  • 1
0
  • 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

Yasir
  • 489
  • 5
  • 11
0

My problem was that my system was using the homebrew version of npm, not the one I installed with tj/n. Once I ran brew uninstall node everything was fine again.

Jan Wirth
  • 411
  • 2
  • 13
0

In my case, deleting the yarn.lock file solved the problem.

Nishant Kumar
  • 691
  • 1
  • 11
  • 31
0

I had this problem. It turned out that I have two VPNs turned on. Once I turned off the VPN that was not meant for this project, it worked. It might worth checking if you need a VPN to run your project or if you need to turn the VPN off before running the project.

Martin Oputa
  • 349
  • 4
  • 6
0

Downgrading node from 20 to 19 helped me (macOS, homebrew):

$ brew unlink node
$ brew install node@19
yegor256
  • 102,010
  • 123
  • 446
  • 597
-2

mine worked using these steps, hope it works for you too.

  1. npm cache clean --force
  2. npm uninstall -g create-react-app
  3. npm uninstall create-react-app and then
  4. 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.