Guide · 5 min read

How to delete node_modules safely (and reclaim 10s of GB)

If you write code on a Mac, the single biggest disk hog is almost never your files - it's the build artifacts scattered across old projects. node_modules alone can be hundreds of MB each, times dozens of repos. Here's how to clear them without breaking anything.

Why it's safe to delete node_modules

node_modules is fully regenerable: it's reinstalled from your package.json / lockfile whenever you run npm install (or pnpm/yarn/bun install). Deleting it doesn't touch your source code. The same is true for most build output - it's derived, not source.

  • node_modules → npm / pnpm / yarn / bun install
  • Xcode DerivedData → rebuilt on next build
  • Rust target/ → cargo build
  • .next, dist, build → next build / your bundler
  • Python .venv / __pycache__ → recreated from requirements

Find them from the command line

To see how much space node_modules folders are using under your projects directory:

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

To delete every node_modules under a folder (review the list above first!):

find ~/dev -name node_modules -type d -prune -exec rm -rf {} +
Tip: Only run this on a projects directory you control (e.g. ~/dev), never your home root. And make sure you can re-run install for those projects.

The safer, faster way

Hand-rolling find/rm works but it's all-or-nothing and easy to point at the wrong folder. TidyBar's Developer mode discovers node_modules, DerivedData, target/, .next, venvs and more across your project roots, shows each with its size and age, lets you pick what to remove - and moves them to the Trash instead of hard-deleting, so a mistake is recoverable. It won't descend into a matched folder or touch anything outside your chosen roots.

Scanning is free, so you can see exactly how many gigabytes of build junk you're sitting on before deciding.

FAQ

Is it safe to delete node_modules?+

Yes - it's regenerated by npm/pnpm/yarn/bun install from your lockfile. Your source code is untouched.

How do I get node_modules back?+

Run your package manager's install command in the project (e.g. npm install) and it's rebuilt.

Does TidyBar delete the right folders?+

It only looks under the project roots you choose, never descends into a matched folder, respects pins, and moves removals to the Trash so they're recoverable.

Do it all in one click with TidyBar

Scan free to see what you can reclaim. $25 one-time · no subscription.

Download TidyBar

More: free up disk space · compare cleaners