How do you delete all node_modules on a Mac?
To delete node_modules on a Mac, remember it is fully regenerable: npm install rebuilds it. A single React project runs 200-500 MB; dozens of old repos quietly eat tens of GB. GRUJ scans your Mac, shows the size of every node_modules, and deletes only those after you confirm. It never touches src or package.json.
brew install --cask fan2dev/tap/gruj 3 months free · no card · direct download (outside the App Store)
Dozens of old repos, each hauling its own node_modules
Every clone, every tutorial, every side project you abandoned still has a node_modules on disk. They don't shrink, they don't share, and Spotlight indexes every one of them. Twenty stale repos at ~300 MB is ~6 GB doing nothing. The usual fix online is find . -name node_modules -type d -prune -exec rm -rf {} + — fast, but one mistyped path and you're deleting the wrong tree with no undo. GRUJ does the same job with sizes shown up front and a confirm step, plus it sweeps the npm/pnpm/yarn/bun caches in the same pass.
The manual way (and its risk)
From a parent folder you can run find . -name 'node_modules' -type d -prune -print to LIST them, then -exec rm -rf {} + to delete. It works, but rm -rf has no confirmation and no undo — a wrong path or a stray space deletes the wrong directory. Always list first, delete second.
gruj scan shows size per folder
Run gruj scan. GRUJ walks your dev directories, finds every node_modules plus the npm/pnpm/yarn/bun stores, and prints the size of each so you decide what's worth deleting — no math with du -sh, no guessing.
gruj clean deletes after you confirm
Pick what to remove and run gruj clean. GRUJ only deletes paths on its regenerable allowlist (node_modules, package-manager caches) and asks before it touches anything. Your code, lockfiles and package.json stay put; npm install rebuilds node_modules whenever you reopen the project.
npm, pnpm, yarn and bun in one scan
GRUJ finds node_modules folders and also the shared stores: ~/.npm, ~/Library/pnpm/store, ~/Library/Caches/Yarn (Yarn 1 classic) and ~/.bun/install/cache. One scan covers all four package managers instead of a separate command for each.
Allowlist: only regenerable junk
GRUJ deletes against a fixed allowlist of regenerable paths. node_modules and caches are in; src/, package.json, lockfiles, .env and git history are not. There is no free-form rm -rf to mistype.
Size before you delete
Every item in gruj scan shows its real on-disk size before you remove anything, so you can target the biggest or oldest repos first instead of nuking everything blindly.
Prune the pnpm/bun store too
Deleting node_modules doesn't reclaim the package-manager cache, which can be several GB on its own. GRUJ prunes the pnpm store and the npm/yarn/bun caches in the same pass, so the freed space is real and not re-downloaded duplicates.
gruj doctor, before touching anything
gruj doctor reports how much reclaimable space sits in node_modules and caches without deleting a single file — a dry run you can read before deciding.
Confirm flow, no surprises
The flow is always scan → pick → confirm. Nothing is deleted until you say so, and GRUJ tells you exactly which paths it will remove.
find/rm by hand vs GRUJ
| GRUJ | By hand / generic | |
|---|---|---|
| See size before deleting | Yes — gruj scan lists size per node_modules | Manual du -sh on each folder |
| Risk of deleting the wrong thing | Low — fixed regenerable allowlist, confirm step | High — one mistyped path in rm -rf, no undo |
| Covers npm/pnpm/yarn/bun caches | Yes, all in one scan | A separate command per tool |
| Confirmation before deleting | Always asks first | rm -rf deletes instantly, silently |
| Target old repos only | Pick per folder from the scan | Manual filtering by hand |
| When the manual command is enough | — | One-off in a single known folder: rm -rf node_modules is fine |
FAQ
What's the best way to delete node_modules on a Mac?
The safest way is to list before you delete. Run gruj scan to see every node_modules with its size, pick the stale repos, then gruj clean removes them after you confirm. By hand it's find . -name 'node_modules' -type d -prune -print to list, then -exec rm -rf {} + to delete — but rm -rf has no undo, so list first.
Is it safe to delete node_modules?
Yes. node_modules holds only installed dependencies, all listed in package.json and your lockfile. Deleting it removes nothing original — running npm install (or pnpm/yarn/bun install) rebuilds it exactly.
How do I find all node_modules folders on my Mac?
Run gruj scan: it walks your dev directories and lists every node_modules with its size. By hand: find . -name 'node_modules' -type d -prune -print from a parent folder lists them without deleting.
Why does node_modules take up so much space?
A single React or Next.js project is typically 200-500 MB because npm copies the full dependency tree, including nested duplicates, per project. With dozens of repos that easily reaches tens of GB.
Can I delete only the old node_modules?
Yes. gruj scan shows each folder with its size so you can pick only stale or abandoned repos and leave active ones alone. node_modules in projects you still use will just rebuild on the next install.
Will deleting node_modules break my project?
No. Your source code, package.json and lockfile are untouched. The project rebuilds the instant you run npm install again; the first install afterwards just takes a bit longer.
Does deleting node_modules clear the npm cache?
No — they're separate. node_modules is per-project; the cache lives in ~/.npm (or the pnpm/yarn/bun store) and can be several GB. GRUJ prunes both in one pass; manually it's npm cache clean --force or pnpm store prune.
How do I prune the pnpm store on Mac?
Run pnpm store prune to drop packages no longer referenced by any project, or let gruj clean handle the pnpm store (~/Library/pnpm/store) alongside node_modules in a single confirmed run.
Reclaim the GB your node_modules are sitting on
Scan every node_modules and package-manager cache across your Mac, see the sizes, delete only what's regenerable. Free right now in early access.
Download free