Every JavaScript project carries its own node_modules, usually 200 MB to 2 GB, and the same packages are copied again in each project. Build tools add their own output next to it: dist, .next, build, Cargo’s target, a Python .venv, CocoaPods’ Pods. Fifty old projects can hold tens of GB of files you can rebuild in a minute.
All of these can be made again from the project’s own files: npm install (or yarn, pnpm install, bun install) reads the lockfile, and a build makes dist or target again. So deleting them is safe for a project you have left alone. Leave them in a project you are working on or that is running right now.
Find the biggest node_modules
The same command works on a Mac and on Ubuntu (replace ~/Developer with where your projects live). -prune stops find from going into each node_modules, so it does not list the thousands of nested ones:
find ~/Developer -name node_modules -type d -prune -exec du -sh {} + 2>/dev/null | sort -h | tail -20
To list only those not modified for 90 days:
find ~/Developer -name node_modules -type d -prune -mtime +90 -print 2>/dev/null
A folder’s date changes only when an entry directly inside it changes, so treat this as a hint and check the project before you delete.
Delete one:
rm -rf ~/Developer/old-project/node_modules
Two things to check first: a project that depends on a package you patched by hand inside node_modules, and a project without a lockfile, which may install newer versions next time.
npkill is a third-party tool, not part of npm, that lists every node_modules under a folder with its size and deletes the one you pick. Run it without installing it:
bunx npkill -d ~/Developer
Build folders
Search for the usual build folders the same way:
find ~/Developer \( -name node_modules -o -name dist -o -name .next -o -name build -o -name target \) -type d -prune -exec du -sh {} + 2>/dev/null | sort -h | tail -30
The names are common words, so check what each one is before you delete it: in some projects a build folder holds source code. What makes each one again:
dist,build,.next,out: the project’s build script (bun run build,npm run build).targetnext toCargo.toml:cargo build.cargo cleaninside the project removes it for you..venvorvenv:uv sync, orpython3 -m venv .venvandpip install -r requirements.txt.Podsnext to aPodfile:pod install.
Xcode’s build folders are not inside your projects: they live in DerivedData, see Xcode taking up too much space.
Why sizes lie a little
pnpm and Bun do not copy packages into each project: they link them from one shared store (hard links, or APFS clones on a Mac). An APFS clone shows its full size in du even though it shares its blocks, and a hard-linked file still exists in the store after you delete the project’s copy. So deleting such a node_modules frees less than du says; the store keeps the files until you clean it (pnpm store prune, bun pm cache rm).
How CleanMate does it
CleanMate lists these folders in Smart Scan on a Mac (all macOS features) and in Developer Junk on Ubuntu (all Ubuntu features). They are never ticked for you.
- Only idle projects. A project counts as stale when it has not changed for 90 days. On a Mac, that means its
package.json, lockfiles, Git index andnode_modules(for build folders: its project files and lockfiles), and those of the folders above it, so a package inside an active monorepo is not listed. - Which build folders. Cargo
target, a Python.venvand CocoaPodsPods, on both systems.dist,.nextandbuildare not listed: those names are too common to tell apart from source folders safely. - Where it looks on a Mac.
~/Developer,~/Projects,~/Code,~/src, and with Full Disk Access~/Documentsand~/Desktop, up to 4 folders down; never inside anothernode_modules, a hidden folder,~/Libraryor through a symlink. - Running projects are skipped on a Mac. A project where node, Bun, pnpm, npm, Yarn or Deno runs (for build folders: cargo, Python, uv or CocoaPods), or that holds an open file, is left out.
- The real size. Files pnpm or Bun share with their store count only what deleting frees: on a Mac, a hard link to a file outside the folder counts nothing and an APFS clone counts only the bytes it does not share.
- Trash or not. On a Mac, both are moved to the Trash, so Undo puts them back. On Ubuntu, build folders go to the Trash (Undo in the message for 10 seconds), but
node_modulesfolders are deleted for good, because an install downloads them again.
If your disk is still full, see Free up disk space on a Mac as a developer or on Ubuntu, old Node, Python and Rust versions, Homebrew eating disk space, Rust, Go and Java package caches and, for game projects, Unity using too much disk space. To compare CleanMate with other cleaners, see the comparison.
The npm, Yarn, pnpm and Bun caches have their own guide: clear the npm, Yarn, pnpm and Bun cache.
FAQ
Is it safe to delete node_modules? Yes. Your package manager’s install command brings it back from package.json and the lockfile. You only lose packages you edited by hand inside it.
How do I delete all node_modules folders at once? find ~/Developer -name node_modules -type d -prune -exec rm -rf {} + deletes every one under that folder, including those of the projects you work on. Run it with -print instead of -exec rm -rf {} + first to see the list.
Does deleting node_modules free the space when I use pnpm? Only part of it: the packages stay in pnpm’s store until you run pnpm store prune.
Can I delete the target folder of a Rust project? Yes, cargo clean does it, and the next cargo build makes it again (that first build takes longer).

