DevCleaner Download .dmg

How to Clean npm, Yarn & pnpm Caches on macOS

JavaScript's package managers never throw anything away. Here's where each one hides its cache, what it costs to clear, and how to hunt down the real disk killer — forgotten node_modules.

Where the caches live

ToolCache locationTypical sizeClean command
npm~/.npm2–10 GBnpm cache clean --force
Yarn (classic)~/Library/Caches/Yarn1–8 GByarn cache clean
Yarn (berry)~/.yarn/berry/cache1–6 GByarn cache clean --all
pnpm~/Library/pnpm/store2–15 GBpnpm store prune
Bun~/.bun/install/cache0.5–3 GBbun pm cache rm
npx~/.npm/_npx0.5–2 GBcleared with the npm cache

All of these are download caches SAFE — packages come back from the registry on the next install. Check what you're sitting on first:

du -sh ~/.npm ~/Library/Caches/Yarn ~/Library/pnpm/store 2>/dev/null

The real disk killer: forgotten node_modules

Caches are bounded; node_modules folders are not. Every tutorial you followed in 2024 left a 300 MB–1 GB folder behind. Find them all, sorted by last touch:

find ~/Projects -name node_modules -type d -prune -exec du -sh {} \; 2>/dev/null | sort -hr

Delete the ones from projects you're done with — npm install recreates them from the lockfile whenever you return. If you prefer an interactive tool, npkill lists and deletes them with arrow keys:

npx npkill

Rule of thumb: the lockfile (package-lock.json, yarn.lock, pnpm-lock.yaml) is the project. node_modules is just its cached expansion.

Don't forget the adjacent caches

Clean all of it in one click

DevCleaner (free, menu bar) scans npm, Yarn and pnpm caches alongside 19 other toolchains — Xcode, Gradle, Homebrew, pip, Cargo and more — rates every category Safe / Warning / Danger and shows exactly how much each will free before you click. An optional auto-clean rule with an age filter keeps the caches from creeping back.

Download DevCleaner — free
free · no account · 4 MB · macOS 14+

FAQ

Is npm cache clean --force safe?
Yes — ~/.npm is purely a download cache. The --force is npm being ceremonial, not a danger sign. npm cache verify is the gentler option that only garbage-collects corrupt entries.
Will deleting node_modules break my project?
No, as long as the lockfile is committed. The next npm install / pnpm install rebuilds it identically. You only lose the time the reinstall takes.
Why does pnpm's store keep growing?
It keeps every package version ever installed by any project until you run pnpm store prune, which drops the ones no project references anymore.