create-react-app : npm ERR! Unexpected end of JSON input while parsing near '....'

Viewed 8595

Describe the bug

npx create-react-app my-app doesn't work for me i tried npm cache clean --force but i get the same error again and again

Steps to reproduce

  1. npm cache clean --force
  2. npm / npx create-react-app front
npm init react-app front
npx: installed 98 in 37.068s

Creating a new React app in /home/h4kst3r/Desktop/APIs/restaurant-API/front.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

npm ERR! Unexpected end of JSON input while parsing near '...zAJNgZjZUkJ08ybAxwNnR'

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/h4kst3r/.npm/_logs/2020-05-20T20_47_49_189Z-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 front/ from /home/h4kst3r/Desktop/APIs/restaurant-API
Done.

System:

OS: Linux 5.4 Ubuntu 20.04 LTS (Focal Fossa)

6 Answers

Its happened because of slow internet . So wait till ur internet connection is normal. Or install all dependencies one by one .

If npx create-react-app my-app command not working and throws an error like: npm ERR! Unexpected end of JSON input while parsing near '...zAJNgZjZUkJ08ybAxwNnR', Just check your npm version:

npm --version 
npm -v

and if required update it:

npm install -g npm@latest

It will definitely work.

First check for npm version by running the following command npm --version. if you have an npm version then try instally npx globally with the help of npm i -g npx. if npm and ngx are installed properlly then this will work .

sudo npm i -g npx --force worked for me.

You should do it as a root user. Open your terminal and type sudo -i or sudo -s. After successful login, the $ prompt would change to # to indicate that you logged in as a root user on Ubuntu. Then if you use `create-react-app it should actually work :)

There are probably two things that can be at fault.

  1. Poor internet connection.
  2. outdated npm version.

update your npm and seek a strong internet connection.

Related