CleanMate

All guides · macOS and Ubuntu · Updated

node_modules and old build folders taking tens of GB: find and delete them safely on Mac and Ubuntu

How to find every node_modules folder and build folder (dist, .next, build, target, .venv, Pods) on a Mac or on Ubuntu, see what each one weighs, and delete the ones of projects you no longer touch without breaking anything.

Download for macOS · Install on Ubuntu — free and open source

CleanMate on a Mac after a Smart Scan cleanup of stale node_modules and build folders, showing the space freedCleanMate on a Mac after a Smart Scan cleanup of stale node_modules and build folders, showing the space freed

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:

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.

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).

Skip the commands

CleanMate runs on both systems: pick yours.

Open source — star it on GitHub: CleanMate for macOS · CleanMate for Ubuntu

How CleanMate decides what is safe to remove →