Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM install fails with mysterious "Unexpected token in JSON" error

Tags:

json

npm

The double space in the subject between "token" and "in" is intentional (edit: SO has stripped the double space!). Opening the NPM log file in nano gives a bit more of a clue;

3911 verbose stack SyntaxError: Unexpected token ^@ in JSON at position 1764 while parsing near '...rsion":"0.2.3","depe^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@...'
3911 verbose stack     at JSON.parse (<anonymous>)
3911 verbose stack     at parseJson (/home/ubuntu/.nvm/versions/node/v8.15.0/lib/node_modules/npm/node_modules/json-parse-better-errors/index.js:7:17)
3911 verbose stack     at consumeBody.call.then.buffer (/home/ubuntu/.nvm/versions/node/v8.15.0/lib/node_modules/npm/node_modules/node-fetch-npm/src/body.js:96:50)
3911 verbose stack     at <anonymous>
3911 verbose stack     at process._tickCallback (internal/process/next_tick.js:189:7)
3912 verbose cwd /home/ubuntu/uat-deployments/app
3913 verbose Linux 4.13.0-38-generic
3914 verbose argv "/home/ubuntu/.nvm/versions/node/v8.15.0/bin/node" "/home/ubuntu/.nvm/versions/node/v8.15.0/bin/npm" "install"
3915 verbose node v8.15.0
3916 verbose npm  v6.7.0
3917 error Unexpected token ^@ in JSON at position 1764 while parsing near '...rsion":"0.2.3","depe^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@...'
3918 verbose exit [ 1, true ]

There is no package-lock.json (though I think npm install should / would generate one). I have done rm -r node_modules and npm cache clean --force.

npm install works fine on my Mac, just not on the build server (Ubuntu). All was working fine previously and package.json has not changed recently. I wonder if a third party dependency's package-lock.json is causing trouble, problem is I have no idea where to look.

Any help appreciated. I'm not an expert in this area.

like image 492
Geoff Clayton Avatar asked Dec 07 '25 10:12

Geoff Clayton


1 Answers

We had the same problem what ended up working for us was changing the NPM registry

Installing create-react-app gives npm ERR! shasum check failed and npm ERR! Unexpected end of JSON input while parsing near '...mojOzGIEI2rg0m24Yb5Oq'

like image 158
Daniel Miron Avatar answered Dec 10 '25 11:12

Daniel Miron