28
votes

I am trying to use npx create-react app but i have errors that is shown below:

npm ERR! Unexpected end of Json input while parsing near
'...eact-app/-/create-rea'

npm ERR! A complete log of this run can be found in: npm ERR!
C:\Users\dp\AppData\Roaming\npm-cache\_logs\2018-12-06T18-42-56-293Z-debug.log

Install for create-react-app@latest failed with code 1** 

and the log file of the error is here...!

How I can get rid of this trouble??

0 info it worked if it ends with ok 1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',

1 verbose cli   
'C:\\Users\\dp\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',

1 verbose cli   'install',

1 verbose cli   'create-react-app@latest',

1 verbose cli   '--global',

1 verbose cli   '--prefix',

1 verbose cli  
'C:\\Users\\dp\\AppData\\Roaming\\npm-cache\\_npx\\3588',

1 verbose cli   '--loglevel',

1 verbose cli   'error',

1 verbose cli   '--json' ]

2 info using [email protected]

3 info using [email protected]

4 verbose npm-session 7862701600d4f4ce

5 silly install loadCurrentTree

6 silly install readGlobalPackageData

7 http fetch GET 304 

https://registry.npmjs.org/create-react-app 872ms (from cache)

8 silly fetchPackageMetaData error for create-react-app@latest
Unexpected end of JSON input while parsing near
'...eact-app/-/create-rea'

9 timing stage:rollbackFailedOptional Completed in 4ms 10 timing
stage:runTopLevelLifecycles Completed in 1693ms 11 verbose stack
SyntaxError: Unexpected end of JSON input while parsing near
'...eact-app/-/create-rea' 11 verbose stack     at JSON.parse
(<anonymous>) 11 verbose stack     at parseJson
(C:\Users\dp\AppData\Roaming\npm\node_modules\npm\node_modules\json-parse-better-errors\index.js:7:17)
11 verbose stack     at consumeBody.call.then.buffer
(C:\Users\dp\AppData\Roaming\npm\node_modules\npm\node_modules\node-fetch-npm\src\body.js:96:50)
11 verbose stack     at process._tickCallback
(internal/process/next_tick.js:68:7) 12 verbose cwd C:\Users\dp 13
verbose Windows_NT 6.3.9600 14 verbose argv "C:\\Program
Files\\nodejs\\node.exe"
"C:\\Users\\dp\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js"
"install" "create-react-app@latest" "--global" "--prefix"
"C:\\Users\\dp\\AppData\\Roaming\\npm-cache\\_npx\\3588" "--loglevel"
"error" "--json" 15 verbose node v10.13.0 16 verbose npm  v6.4.1 17
error Unexpected end of JSON input while parsing near
'...eact-app/-/create-rea' 18 verbose exit [ 1, true ]
21
try npm cache clean --force then run npm install -g create-react-app@latest - Satish Patel
it was the right command, thanks a lot. - zanjan_citizen
your problem is solved with npm cache clean --force command?? - Satish Patel
try npm cache clean --force then run npx create-react-app project_name --template all - Chaurasia

21 Answers

91
votes

To fix the issue, run these commands in sequence

npm init
npm install create-react-app
npx create-react-app myapp
25
votes

I had the same issue "Install for create-react-app@latest failed with code 7" Use this. It worked for me.

npm install -g create-react-app    
npx create-react-app my-app     
cd my-app      
npm start     

for further reference go to: https://www.techomoro.com/how-to-install-and-setup-a-react-app-on-windows-10/

19
votes

Clean npm cache:

npm cache clean --force

then try again

12
votes

First, clear cache by typing this in your terminal:

npm cache clean --force

Then upgrade your version of npm by either following these steps or type:

npm install -g npm@next

Now go to "NodeJS" in Programs and Features in your Windows settings and Repair your installation.

Restart terminal and type:

npx create-react-app my-app

This should hopefully fix your issue.

6
votes

I had the same problem in creating react project when I used commands from official source https://reactjs.org/docs/create-a-new-react-app.html#create-react-app

npx create-react-app my-app
cd my-app
npm start

The above commands din't work on my windows. I have Node >= 6 and npm >= 5.2 on my machine even then it is not able to open localhost:3000 then I used this commands

npm install -g create-react-app
create-react-app my-app-name
cd my-app-name
npm start

It worked perfectly fine. I learned from https://www.youtube.com/watch?v=pCgDRgmfilE

3
votes

This worked for me!!

first you need to create the package.json file by npm init

then npx create-react-app myapp

1
votes

Sometime it happens because of slow internet speed. Try with this one.

 npx create-react-app <app name> -timeout=60000

Default timeout=30000(30sec). increase timeout, if you necessary.

1
votes
  • In your antivirus whitelist the node software

  • hey guys in my point of view, check your system any antivirus is running and blocking the node.exe more specifically (ByteFence Anti-malware)

  • In my case its blocking the node system call

  • I quit this from hidden icons in the system tray it works fine for me

when you do => npm start

  • you may have seen some antivirus asks permission to add it to whitelist or add it to block list that antivirus you should stop or add whitelist to it
1
votes

Same issue, and here is my solution.

npm cache clear --force

enter image description here

1
votes

there is bug because your user pc name contains space , you could resolve this with this code :

> npm config set cache "C:\Users\mycomputer~1name\AppData\Roaming\npm-cache" --global
0
votes

Run Windows PowerShell as administrator and type this:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

0
votes
npm uninstall -g create-react-app
npx create-react-app my-app

You don't need to install the create-react-app package globally. 'npx' is already installing with the latest version.

Quick start

0
votes
  1. In your antivirus whitelist the node software

  2. hey guys in my point of view, check your system any antivirus is running and blocking the node.exe more specifically (ByteFence Anti-malware)

  3. In my case its blocking the node system call

  4. I quit this from hidden icons in the system tray it works fine for me

when you do

npm start

  • sometimes you may seen some antivirus asks permission to add it to whitelist or add it to block list that antivirus you should stop or add whitelist to it

0
votes

I tried everything and nothing worked.

I then restarted my laptop, and when I tried npm init followed with npm install create-react-app I got an Avast potential harmful file alert, but it was ok and I confirmed it. That create-react-app attempt failed, but when I tried it again it worked.

It's possible that a firewall or such is blocking node from carrying out a function, hence why it's throwing a callback() never called error.

0
votes

The problem arises due to so many reasons.

    1. This happens is if one of the node modules requires to install your react app is missing.
    1. The other reason is if your have and unstable network connection.
    1. Sometimes, but on rare cases, your antivirus may assume the cmd files in your cache to be malware.

if your antivirus is your issue, disable it for the period you run the commands.

Whatever the reason for npx create-react-app is not working on your machine, run the following commands in sequence:

npm cache clean --force 
npx create-react-app my-app  

let me know if this worked for you

0
votes

This worked for me: because i had network issues

npx create-react-app <app name> -timeout=60000
0
votes

npm cache clean --force

npx create-react-app project_name --template all

cd project_name

npm start

0
votes

try this:

npm cache clean --force
npx create-react-app myapp

It worked for me.

0
votes

This worked for me.

npm cache clean --force
npm init -y
npx create-react-app my-app
-1
votes
  1. sudo chown -R 1000:1000 "/home/aditya/.npm"
  2. npx crate-react-app

this should fix the issue.

-1
votes

If you are unable to create the app try reinstalling nodeJS in 32-bits and try it.