node_modules and npm Cache: Reclaiming Developer Disk Space

node_modules and npm Cache: Reclaiming Developer Disk Space
Short answer

The npm cache (~/.npm/_cacache) is pure cache — safe to clear, re-downloaded on demand. node_modules folders are rebuildable from your lockfile with a reinstall, so they're safe to delete for projects you're not actively building. Both together often hold 5–40 GB on a developer Mac.

Why it gets so big

Every project keeps its own node_modules, and every install adds to a global cache. Ten old side projects can easily hold more bytes than your photo library — and you'll never open nine of them again.

The global caches

All of these are re-downloaded when needed. The only cost is bandwidth on your next install.

Old node_modules

For dormant projects, deleting node_modules is safe as long as the lockfile is committed — npm ci rebuilds it exactly. Find the big ones:

find ~/Developer -name node_modules -type d -prune -print0 | xargs -0 du -sh | sort -hr | head

Check the project is committed and pushed first. A rebuilt node_modules is free; uncommitted work isn't.

The measuring problem

du is honest but slow across dozens of projects, and it's easy to delete the wrong thing at 1 a.m. MacCleaner measures package caches and rebuildable project files, shows the real byte counts per item, and keeps everything recoverable until you empty it.

Frequently asked questions

Is it safe to delete node_modules?

Yes, if your lockfile is committed. npm ci or an equivalent install rebuilds it identically.

Does clearing the npm cache break anything?

No. It's a download cache — packages are fetched again as needed.

How much space do package caches use?

5–40 GB is typical on an active developer Mac across npm, pnpm, Homebrew and pip.

See where your space actually went

MacCleaner scans read-only, shows you every file before anything is touched, and lets you choose Trash or permanent. Free for up to 500 MB of cleanup a day.

Download for Mac