50

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 npm@6.4.1

3 info using node@v10.13.0

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 ]
Sanjeev
  • 4,255
  • 3
  • 28
  • 37
zanjan_citizen
  • 519
  • 1
  • 4
  • 7

28 Answers28

135

To fix the issue, run these commands in sequence

npm init
npm install create-react-app
npx create-react-app myapp
Sanjeev
  • 4,255
  • 3
  • 28
  • 37
Qalib Abbas
  • 1,351
  • 1
  • 6
  • 3
43

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/

webpersistence
  • 894
  • 3
  • 12
  • 29
Amal K George
  • 431
  • 4
  • 4
25

Clean npm cache:

npm cache clean --force

then try again

BOOMHUNK
  • 356
  • 3
  • 6
12

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.

Raisa A
  • 437
  • 7
  • 21
10

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

Raman Kumar
  • 371
  • 3
  • 11
4

This worked for me!!

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

then npx create-react-app myapp

Community
  • 1
  • 1
1
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

yunusunver
  • 530
  • 6
  • 16
1

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.

SaimumIslam27
  • 971
  • 1
  • 8
  • 14
1

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

hubnotch
  • 31
  • 1
  • 6
  • This worked for me. The first time I tried the npx command everything seemed to be going well until it printed out "A template was not provided". I ran the "npm cache clean --force" and then ran the npx command and this time it installed the template dependencies as expected. Thank you! – Dale Moore Aug 23 '21 at 00:16
1
  • 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
  • Thank you so much. It really helped a lot. I kept on trying all the solution but didn't work. Issue was due to antivirus only. – Komal Feb 18 '21 at 13:58
1

Same issue, and here is my solution.

npm cache clear --force

enter image description here

Royer Adames
  • 868
  • 9
  • 13
1

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
1

I ran into this kind of problem. It took a lot of googling and experimenting to come up with a standard solution that will require no hassle at all. You don't need to clear any cache or make any folder changes I found out that whenever I run

npx create-react-app myapp

I get this error

A template was not provided. This is likely because you're using an outdated version of create-react-app.

To solve this issue and subsequent issue that might arise using npx, do either of the following: NB: Install volta before using volta. Make sure you have node installed..

npm install npx
volta install npx

I highly recommend that you use volta to manage your dependencies as it is faster and its flexible to use. it install the latest of any package you want to install unless you indicate otherwise. Get volta here.

When you're done updating npx, your npx error will of the past. Reach out if you encounter any errors.

hubnotch
  • 31
  • 1
  • 6
0
  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

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.

jonn
  • 1
0

This worked for me.

npm cache clean --force
npm init -y
npx create-react-app my-app
0

This worked for me: because i had network issues

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

npm cache clean --force

npx create-react-app project_name --template all

cd project_name

npm start

Chaurasia
  • 494
  • 1
  • 6
  • 22
0

If you're using a VPN it will fail. In my case it said:

npm ERR! code ETARGET
npm ERR! notarget No matching version found for loader-utils@^2.0.4.
npm ERR! notarget In most cases you or one of your dependencies are 
requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! A complete log of this run can be found in: ...

Needless to say I tried everything until I started doubting my life, career and everything in between, and then gave the "it's a network issue" try with 0 confidence.

And it worked.

Marghen
  • 255
  • 2
  • 6
0

Here is my solution. Uninstall nodejs and reinstall nodejs again. After that, run these commands:

npm i
npm i -g create-react-app
npm i create-react-app
npm init
npx create-react-app my-app

That worked for me. The main issue was my nodejs was not up-to-date, and I have unstable network connection. That's why had to reinstall nodejs.

0

I had this same issue but now found a solution and I think this is the simplest way to do it.

goto path :

C:\Users\YOUR USER NAME HERE\AppData\Roaming\

and create a new folder called "npm"

now bug fixed

0

npx create react app not working :

Problem: if you are facing create-react-app issue

Solution:

  1. npm init
  2. npm install create-react-app
  3. npx create-react-app myapp
-1

Run Windows PowerShell as administrator and type this:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

reyhane
  • 183
  • 1
  • 15
-1

try this:

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

It worked for me.

  • 1
    Please try to add why these commands should be executed and what they perform , as it shouldn't cause any further error for the user – Goutham J.M Apr 30 '21 at 07:21
-1

please run npm cache clean --force

If you are using VS code, please make sure you restart the terminal.

It will be okay to start the new project.

Jaden
  • 192
  • 4
  • 15
-1

First create a folder with

Mkdir (folder name)

Second Cd into the folder

Cd folder_name

Thirdly run npx create-react-app ./

This will create a new react app for you.

-1

First download new version of Node Which is version 17 now in April 2022,

Secondly make directory mkdir appName Thirdly cd appName Lastly npx create-react-app ./

This is how to get Reactjs application in React 18.

-2
  1. sudo chown -R 1000:1000 "/home/aditya/.npm"
  2. npx crate-react-app

this should fix the issue.