57

I am trying to use the npx create-react app, but I have errors that are 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 ]
4
  • 17
    try npm cache clean --force then run npm install -g create-react-app@latest Commented Dec 6, 2018 at 19:02
  • it was the right command, thanks a lot. Commented Dec 7, 2018 at 10:02
  • your problem is solved with npm cache clean --force command?? Commented Dec 7, 2018 at 11:40
  • 1
    try npm cache clean --force then run npx create-react-app project_name --template all Commented Mar 17, 2021 at 5:50

30 Answers 30

153

To fix the issue, run these commands in sequence

npm init
npm install create-react-app
npx create-react-app myapp
Sign up to request clarification or add additional context in comments.

4 Comments

Worked - Windows 10
it's working thanks. But why it not working direct command(npx create-react-app frontend) in windows?
I did not required first step.
Thanks, it solved my problem. But I did not understand the use of the npm init, it is important.
50

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/

1 Comment

Thanks for your answer. your solution worked, but I do not understand why npx create-react-app hello-world not working.
26

Clean npm cache:

npm cache clean --force

then try again

Comments

14

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.

Comments

12

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

1 Comment

the below set of commands works for me...but npx one doesn't...Can you tell why this happens?
5

This worked for me!!

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

then npx create-react-app myapp

1 Comment

this is the only solution that worked for me
4
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

Comments

3

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 Comment

npm init followed by this solved the issue for me on a min-provisioned CentOS 9 VM and a VPN connection in Australia
2

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

1 Comment

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!
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

1 Comment

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.
1

Same issue, and here is my solution.

npm cache clear --force

enter image description here

Comments

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

Comments

1

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

Comments

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 installs 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 be of the past.

Comments

1

if you are facing create-react-app issue

Fix:

npm init

npm install create-react-app

npx create-react-app myapp

Comments

0

Run Windows PowerShell as administrator and type this:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Comments

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

Comments

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.

Comments

0

This worked for me: because i had network issues

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

Comments

0

npm cache clean --force

npx create-react-app project_name --template all

cd project_name

npm start

Comments

0

This worked for me.

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

Comments

0

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.

1 Comment

Please just stop
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 Comment

Please review Why not upload images of code/errors when asking a question? (e.g., "Images should only be used to illustrate problems that can't be made clear in any other way, such as to provide screenshots of a user interface.") and do the right thing (it covers answers as well). Thanks in advance.
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.

2 Comments

Why does it fail with a VPN?
I am not sure, I didn't dig deeper tbh. I was using Cloudflare warp and VPN at the time, but I'd sure love to know. It seems weird
0

Here is my solution. Uninstall Node.js and reinstall Node.js 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 Node.js was not up-to-date, and I have unstable network connection. That's why had to reinstall Node.js.

Comments

0

I just tried all the solutions above but none of them works for me :(

so, maybe if somebody has issues with create-react-app, I think u should give a try for vite

I switch to vite and no more problems, not sure what is the cause, I also use latest version of nodejs v20.13.1

If anyone gets this error, pls share :(

Update: I use Ubuntu for this in corp, in my PC, no issues with create-react-app

Comments

-1

try this:

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

It worked for me.

1 Comment

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
-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.

Comments

-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.

2 Comments

Please stop repeating others' answers. And not only on this question
It was a mistake sir, Noted.
-2
  1. sudo chown -R 1000:1000 "/home/aditya/.npm"
  2. npx crate-react-app

this should fix the issue.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.