npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

npm leaves corrupted write-protected cache and can't auto cleanup it. leads install always failed

What I Wanted to Do

npm install to install packages

What Happened Instead

npm failed with erros like
npm ERR! Unexpected end of JSON input while parsing near ‘…dist":{“shasum”:"0970’

after that , npm install never success. no package-lock.json appeared. manually delete cache file resolve this.

seems that this related to install pg 7.8.2

npm cache has such entry (which error printed) as


this file is 46K and is not a valid json , and it’s write-protected

Reproduction Steps

firstly I’ve successfully installed all packages by running npm up ,
after this , I switched to different user account and run npm install to same project (clean checkout from git , just same as successfully installed ones), and npm failed, never successfully run , until I’ve manually delete the invalid cache file.
during delete ,I’ve found this file is write-protected


and invalid cache file here (due to upload restriction I’ve add .json suffix)
6326a85a4b4bb3f58f6270a92b2cde0f9eef20d98105411275119e86c410e721f74126d3bc2209b34eb958062ad314d5a967c29ccce8f8f865a86f5620c8.json (45.9 KB)

Platform Info

$ npm --versions

$ node -p process.platform

I'm on archlinux  64bit
with nodejs-lts-dubnium 10.15.3-1

This issue might be relevant, files left behind after using sudo for global installs: Global installs (sudo npm i -g) fail on Mac after 6.5 upgrade. Works fine after 6.4.1 downgrade.

Edit: see response from Lars for more likely explanation.

There was a problem with corrupt responses in the Ireland region a few days ago. While the cache should sort itself out after a while (possibly with --prefer-online), deleting the entry works too. If you think something else is going on, or if it happens again, please do let us know.

Thanks for your response. I’m using npm in China (which https connection is not very stable), I’ve observed such problem multiply times. Haven’t dig npm source yet, but I wonder if npm can only persist valid cache, or auto cleanup invalid entry immediately ? a invalid cache prevent any following install seems unreasonable to users. for example we have npm install as a jenkins auto build stage, neither always bypass local cache nor manually delete invalid cache is good idea .

Thanks for the information, I didn’t run npm by sudo nor install to global locations, just using npm as regular user.

This problem happen again … with npm 6.9.0.
I think npm should at least print the corrupted file path to ease debug… I can only find corrupt file by grep the limited context from npm error log. (it has mulit matches in different files) . this time it is puppeteer cache. I’m surprised that such problem happened so frequently (to me only? interesting.)