Search code examples
node.jsnpmnpm-install

NPM install error "Unexpected token < in JSON at position 0"


I'm using npm install and validate the package JSON content is valid and I'm getting the following error:

After reading on the web, I did "rm -f package-lock.json && npm install" (even if I didn’t see any package lock there) and did also npm cache clean -f which doesn’t help, also configured registry.

See Can't install any package with node npm

I'm using the latest npm, 6.2.0.

The error in the logs is:

159 silly saveTree ├── [email protected]
159 silly saveTree ├── [email protected]
159 silly saveTree └── [email protected]
160 verbose stack SyntaxError: Unexpected token < in JSON at position 0 while parsing near '<html>
160 verbose stack <head><title>...'
160 verbose stack     at JSON.parse (<anonymous>)
160 verbose stack     at parseJson (/usr/local/lib/node_modules/npm/node_modules/json-parse-better-errors/index.js:7:17)
160 verbose stack     at consumeBody.call.then.buffer (/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/body.js:96:50)
160 verbose stack     at <anonymous>
160 verbose stack     at process._tickCallback (internal/process/next_tick.js:188:7)

Is there is something else I can do?


Solution

  • Your package.json, or maybe other JSON file is incorrect. You must first fix JSON errors.