The npm cache is huge¶
npm keeps every package tarball and metadata response it ever downloaded in
~/.npm/_cacache (%LocalAppData%\npm-cache on Windows) and never removes anything
on its own. After a year or two it's commonly 10–40 GB.
The blunt fix¶
This deletes everything, so your next installs re-download every package, even the ones you use daily.
Remove only what you don't use¶
diskdiet removes entries written more than 30 days ago (change with --older-than),
plus old npx installs and logs, and keeps the rest:
- it reads npm's cache index to know when each entry was written,
- rewrites the index without the old entries,
- removes content no remaining entry points at (content shared with a newer entry stays).
npm cache verify reports a healthy cache afterwards, and packages you installed recently
still install offline.
Check first¶
Related¶
- Old node_modules folders, the other big npm-related space user.
- pnpm users: diskdiet runs
pnpm store prune(see What diskdiet cleans).