Mopup › Guides › node_modules

How to find and delete old node_modules folders

Every JavaScript project keeps its dependencies in a node_modules folder, often hundreds of megabytes each, and projects you finished months ago keep theirs too. Deleting them is safe when the project has a lockfile: one install brings everything back.

Find them and their sizes

Replace ~/Projects with the folder you keep your code in. This lists every node_modules folder with its size, smallest first, and changes nothing:

find ~/Projects -name node_modules -type d -prune -exec du -sh {} + 2>/dev/null | sort -h

Delete the ones you don't need

One project's folder:

rm -rf ~/Projects/old-app/node_modules

Or every node_modules folder under ~/Projects:

find ~/Projects -name node_modules -type d -prune -exec rm -rf {} +

That deletes them for good, in every project under that folder, including the ones you're working on. When you come back to a project, run npm install, pnpm install, yarn or bun install in it. If you'd rather pick folders from a list, npx npkill shows them in Terminal and deletes the ones you choose.

Other folders your tools recreate

The same goes for other generated folders: .next and .nuxt, .turbo, .parcel-cache, .svelte-kit, .angular, target in Rust and Maven projects, .build in Swift packages, Pods, .gradle, and build in Gradle and Flutter projects. Python's .venv comes back too, but only once you create it and install the packages again. Check that a folder really is generated before deleting it: a folder called build can also be your own.

Clear package manager caches

Why sizes can mislead

pnpm and Bun don't copy every package into every project. They link or clone them from one shared store, so the same files appear in many node_modules folders. Finder and du can count those files once per folder, so deleting one folder may free much less than its size suggests.

Mopup's Projects section on a demo Mac: merged git worktrees with their pull request numbers, what removing each one frees next to the bigger size Finder shows, and 13 items selected for 23.5 GB.

Related guides