1
votes

I'm using Ubuntu 20.04. I've been trying to run create react app using npx for over 2 days switching to different Wifis + Ethernet but I get Invalid json response body at https://registry.npmjs.org/loose-envify all the time.

I thought it was an internet speed connection problem but it wasn't

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

npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! invalid json response body at https://registry.npmjs.org/loose-envify reason: Unexpected end of JSON input

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/deestarks/.npm/_logs/2021-04-12T18_55_27_266Z-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

2
Can you share your package.json file? Or is that the issue, it has an error and then gets deleted? What command are you running to create this new React project? - Drew Reese
@DrewReese I don't have a package.json. It gets deleted when the error occurs. And I issue the command with npx create-react-app appname - DeeStarks
And any extra details in the generated log: /home/deestarks/.npm/_logs/2021-04-12T18_55_27_266Z-debug.log? Do you have the required versions of Node/npm installed: create-react-app.dev/docs/getting-started#creating-an-app. - Drew Reese
No extra details - DeeStarks

2 Answers

1
votes

I had and resolved similar issue here: npm install failed, npm ERR! invalid json response

npm cache clean --force

and

npm cache verify

then

npm i npm@latest -g

and finally, I was able to run

npm i

The similar question was there: npm ERR! Unexpected end of JSON input while parsing near '...registry.npmjs.org/@i'

0
votes

run this command and it will solve your issue

sudo npm cache clean --force