Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/react-is (over 30000ms)

When I want to create a react app I'm encountering the following error:

npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/react-is (over 30000ms)

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\info\AppData\Roaming\npm-cache\_logs\2020-04-23T02_54_45_865Z-debug.log

Aborting installation.
  npm install --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.

Deleting generated file... package.json
Deleting app2/ from C:\Users\info
Done.
like image 245
devZack Avatar asked Apr 23 '20 03:04

devZack


3 Answers

Sounds like you have a slow connection. Try increasing the timeout from 30s to 60s by adding this to your .npmrc file:

timeout=60000

You could also try adding

prefer-offline=true

if you are trying to save bandwidth or have a slow connection

Note: if you don't have an .npmrc file setup yet, you can create one here

  • for Windows: C:\Users\{username}\.npmrc
  • for Mac/Linux ~/.npmrc

Or you can create one in the same directory as your project's package.json file.

like image 99
Carl von Buelow Avatar answered Nov 16 '22 17:11

Carl von Buelow


I had a slow connection and I updated the timeout value to .npmrc using:

npm set timeout=100000

And to check if the value is updated (Mac): vi ~/.npmrc

like image 15
Sree.Bh Avatar answered Nov 16 '22 16:11

Sree.Bh


Users are extremely likely to face this issue if they are on a slow internet connection. To counter this, you need to increase the timeout in the npm's config file. And here's how to do it:

  1. Find the .npmrc file (located in the nodejs installation folder; in my case, it's in F:\Installations\nodejs\node_modules\npm folder. But for you, it might be in C:\program files folder).
  2. Open the .npmrc file and append this line: timeout=240000 (usually it is 60 seconds I suppose, but since my connection was way slower therefore, I had to increase it to 240 seconds or 4 minutes, you can keep it 120000 for 120seconds)
  3. Save the file

Since create-react-app fails midway, it can easily break npm's package.json file thus leading to this sort of issue:

Unexpected end of JSON input while parsing near

Therefore, before running the npx create-react-app, run the following command: npm cache clean --force as it cleans the cache and (i think) repairs the package.json file.

like image 8
dev404 Avatar answered Nov 16 '22 16:11

dev404