pacote
pacote copied to clipboard
npm install fails throwing an error because of wrong entry in cache
When I run npm install in preact-cli, I was getting the following error:
verbose stack SyntaxError: Unexpected end of input at 1:51497
verbose stack 3","cookie":"0.0.3","crc":"0.2.0","fresh":"0.1.0","methods":"0.0.1","
verbose stack ^
verbose stack at Object.parseJSON (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/node_modules/json-parse-helpfulerror/node_modules/jju/lib/parse.js:745:13)
verbose stack at parse (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/node_modules/json-parse-helpfulerror/index.js:10:13)
verbose stack at consumeBody.call.then.buffer (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/src/body.js:96:50)
verbose stack at <anonymous>
verbose stack at process._tickCallback (internal/process/next_tick.js:188:7)
verbose cwd /Users/reznord
verbose Darwin 16.7.0
verbose argv "/usr/local/Cellar/node/8.3.0_1/bin/node" "/usr/local/bin/npm" "install" "-g" "preact-cli"
verbose node v8.3.0
verbose npm v5.3.0
error Unexpected end of input at 1:51497
error 3","cookie":"0.0.3","crc":"0.2.0","fresh":"0.1.0","methods":"0.0.1","
error ^
Ideally rm -rf node_modules && npm i --prefer-online
should force the cache, but that didn't work too throwing the same error as before:
➜ preact-cli git:(master) rm -rf node_modules && npm i --prefer-online
npm ERR! Unexpected end of input at 1:51497
npm ERR! 3","cookie":"0.0.3","crc":"0.2.0","fresh":"0.1.0","methods":"0.0.1","
npm ERR! ^
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/reznord/.npm/_logs/2017-08-16T07_03_47_851Z-debug.log
Setting it to an empty cache worked for me: npm i --cache /tmp/npm-empty
As a last resort, I cleared the cache using npm cache clean --force
and then an npm install
works like a charm 😄
I'm pretty concerned about invalid/incomplete data making it into the cache. I bet this is streams being assholes again -- it might be worth making it so make-fetch-happen
verifies Content-Length
of the data it's collected.
It's actually unclear whether this is a hiccup with node, with m-f-h, or if a server is literally actually sending invalid data. Either way, it shouldn't be cached.