npm ERR! Unexpected end of JSON input while parsing

registry
priority:high
triaged

(Thomas Flori) #1

What I Wanted to Do

Installing node dependencies defined in package.json

What Happened Instead

I got the error message: npm ERR! Unexpected end of JSON input while parsing

Reproduction Steps

It is reproducible when it appears. Even a npm cache clean --force does not help. Unfortunately it is not clear for me when it happens.

Details

The package differs from time to time but I’m facing this problem now for at least the 6th time.

And event after a npm cache clean --force I get this error line in the log:

427 http fetch GET 200 https://registry.npmjs.org/autoprefixer 9ms (from cache)

It was loaded during the the installation but it seems that it is not stored correctly in the cache - the package meta itself does not have an error in the json.

Here are the relevant parts of the log file:

0 info it worked if it ends with ok
1 verbose cli [ '/home/wwwxfer/.nvm/versions/node/v8.11.3/bin/node',
1 verbose cli   '/home/wwwxfer/.nvm/versions/node/v8.11.3/bin/npm',
1 verbose cli   'install' ]
2 info using npm@6.4.0
3 info using node@v8.11.3
4 verbose npm-session 6b88e163950972fe
...
40 http fetch GET 200 https://registry.npmjs.org/autoprefixer-core 103ms
...
47 silly pacote range manifest for autoprefixer-core@^5.1.7 fetched in 121ms
48 http fetch GET 200 https://registry.npmjs.org/autoprefixer 374ms
...
51 silly fetchPackageMetaData error for autoprefixer@^5.2.0 Unexpected end of JSON input while parsing near '...yPWXRQjBUaGj5uTiKjJGd'
...
427 http fetch GET 200 https://registry.npmjs.org/autoprefixer 9ms (from cache)
428 silly fetchPackageMetaData error for autoprefixer@^5.2.0 Unexpected end of JSON input while parsing near '...yPWXRQjBUaGj5uTiKjJGd'
429 timing stage:rollbackFailedOptional Completed in 0ms
430 timing stage:runTopLevelLifecycles Completed in 2012ms
431 silly saveTree FMPreporter@1.0.0
431 silly saveTree ├── grunt-autoprefixer@3.0.4
431 silly saveTree ├── grunt-contrib-concat@0.5.1
431 silly saveTree ├── grunt-contrib-less@1.4.1
431 silly saveTree ├── grunt-contrib-uglify@0.9.2
431 silly saveTree ├── grunt-contrib-watch@0.6.1
431 silly saveTree ├── grunt-shell@1.3.1
431 silly saveTree ├── grunt-template@0.2.3
431 silly saveTree └── grunt@1.0.3
432 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...yPWXRQjBUaGj5uTiKjJGd'
432 verbose stack     at JSON.parse (<anonymous>)
432 verbose stack     at parseJson (/home/wwwxfer/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/json-parse-better-errors/index.js:7:17)
432 verbose stack     at consumeBody.call.then.buffer (/home/wwwxfer/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/node-fetch-npm/src/body.js:96:50)
432 verbose stack     at <anonymous>
432 verbose stack     at process._tickCallback (internal/process/next_tick.js:188:7)
433 verbose cwd /data/tmp/gr_fmp_handball/87b44799/0/FMP/fmp-handball/scouting/EMR
434 verbose Linux 3.16.0-6-amd64
435 verbose argv "/home/wwwxfer/.nvm/versions/node/v8.11.3/bin/node" "/home/wwwxfer/.nvm/versions/node/v8.11.3/bin/npm" "install"
436 verbose node v8.11.3
437 verbose npm  v6.4.0
438 error Unexpected end of JSON input while parsing near '...yPWXRQjBUaGj5uTiKjJGd'
439 verbose exit [ 1, true ]

Platform Info

$ npm --versions
{ npm: '6.4.0',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.8.0',
  icu: '60.1',
  modules: '57',
  napi: '3',
  nghttp2: '1.32.0',
  node: '8.11.3',
  openssl: '1.0.2o',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.19.1',
  v8: '6.2.414.54',
  zlib: '1.2.11' }
$ node -p process.platform
linux

(Kat Marchán) #2

This almost always means you got an incomplete response from the registry but it still responded with 200. I’m surprised it’s so consistent for you. I can’t repro this myself for this package, unfortunately – is it always with the same one, or does it vary?


(Thomas Flori) #3

That’s also my problem. The package varies and when I request it from browser it’s fine too. I have to admit that the server sits behind a firewall and there is a prody between maybe that’s also why it is consistent.

Could we not catch such errors and request the package with a cache buster instead of throwing?


(mdeliw) #4

8 silly fetchPackageMetaData error for @vue/cli@latest Unexpected token < in JSON at position 0 while parsing near ‘<!DOCTYPE html PUBLI…’
9 timing stage:rollbackFailedOptional Completed in 0ms
10 timing stage:runTopLevelLifecycles Completed in 386ms
11 verbose stack SyntaxError: Unexpected token < in JSON at position 0 while parsing near ‘<!DOCTYPE html PUBLI…’

consistently fails for npm install - g @vue/cli. Same results with yarn.
| => nvm ls
-> v11.2.0
default -> node (-> v11.2.0)