9

I had already install npm before, but somehow I had to uninstall it for some reason. Now, i tried to install npm again to create react app with this command.

npx create-react-app ip_tracker

On a halfway installation I found this error

npm ERR! code FETCH_ERROR npm ERR! errno FETCH_ERROR npm ERR! invalid json response body at https://registry.npmjs.org/@babel%2fpreset-react reason: Unexpected end of JSON input npm ERR! A complete log of this run can be found in: npm ERR! /home/ngebelcilik/.npm/_logs/2020-11-27T14_34_28_241Z-debug.log 

Here's the logs

0 verbose cli [ 0 verbose cli '/usr/bin/node', 0 verbose cli '/usr/share/nodejs/npm/bin/npm-cli.js', 0 verbose cli 'exec', 0 verbose cli '--', 0 verbose cli 'create-react-app', 0 verbose cli 'ip_tracker' 0 verbose cli ] 1 info using [email protected] 2 info using [email protected] 3 timing config:load:defaults Completed in 7ms 4 timing config:load:file:/usr/share/nodejs/npm/npmrc Completed in 10ms 5 timing config:load:builtin Completed in 10ms 6 timing config:load:cli Completed in 8ms 7 timing config:load:env Completed in 3ms 8 timing config:load:project Completed in 4ms 9 timing config:load:file:/home/ngebelcilik/.npmrc Completed in 1ms 10 timing config:load:user Completed in 1ms 11 timing config:load:file:/etc/npmrc Completed in 1ms 12 timing config:load:global Completed in 1ms 13 timing config:load:cafile Completed in 1ms 14 timing config:load:validate Completed in 1ms 15 timing config:load:setUserAgent Completed in 2ms 16 timing config:load:setEnvs Completed in 4ms 17 timing config:load Completed in 44ms 18 verbose npm-session 9047ea92ff92abbf 19 timing npm:load Completed in 86ms 20 http fetch GET 200 https://registry.npmjs.org/create-react-app 835ms 21 timing arborist:ctor Completed in 4ms 22 timing arborist:ctor Completed in 1ms 23 timing arborist:ctor Completed in 1ms 24 timing command:exec Completed in 416430ms 25 verbose stack Error: command failed 25 verbose stack at ChildProcess.<anonymous> (/usr/share/nodejs/npm/node_modules/@npmcli/promise-spawn/index.js:64:27) 25 verbose stack at ChildProcess.emit (events.js:314:20) 25 verbose stack at maybeClose (internal/child_process.js:1021:16) 25 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) 26 verbose cwd /home/ngebelcilik 27 verbose Linux 5.4.0-51-generic 28 verbose argv "/usr/bin/node" "/usr/share/nodejs/npm/bin/npm-cli.js" "exec" "--" "create-react-app" "ip_tracker" 29 verbose node v12.19.0 30 verbose npm v7.0.11 31 error code 1 32 error path /home/ngebelcilik 33 error command failed 34 error command sh -c create-react-app ip_tracker 35 verbose exit 1 

I already doing research on this error, it's similiar with this problem, but this problem happened everytime I install any npm packages (not just react).

2
  • Are you behind a proxy or something? Commented Nov 27, 2020 at 15:09
  • 2
    It might be a local caching issue. Can you please run npm cache clean --force and then try again? Commented Dec 1, 2020 at 4:25

3 Answers 3

24

Viral Patel comment solved it for me. Problem was solved by cleaning the local cache with.

npm cache clean --force 
Sign up to request clarification or add additional context in comments.

3 Comments

it didnt work for me
~ $ npm cache clean --force npm WARN using --force Recommended protections disabled.
This worked for me, but I had to do: sudo chown -R 501:20 'Users/[user_name]/.npm' first.
1

In my case I just ran the npm install again, it took a long time but it worked. It could have been a network issue.

Comments

0
npm ERR! invalid json response body at https://registry.npmjs.org/@babel%2fpreset-react reason: Unexpected end of JSON input 

This means you are getting bad JSON in the response. There could be a number of reasons you get that error ranging from a network issue on your end to an issue with the npm servers. fwiw that resource does return valid json for me...

Try to curl the resource and see if the response is JSON:

curl https://registry.npmjs.org/@babel%2fpreset-react | python -m json.tool 

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.