How to delete node_modules folders safely

Every JavaScript project keeps its own copy of its packages. Old projects can hold many gigabytes.

Find them and their sizes

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

Is it safe?

Yes, for the folder itself: npm install (or yarn, pnpm install) rebuilds it from package.json and the lock file. What is not safe is deleting the project around it when it has work that was never committed or pushed.

Remove one

rm -rf ~/projects/old-app/node_modules
Commit and push first, or check with git status that the project has no uncommitted changes. rm -rf skips the Trash and cannot be undone.

Package caches too

npm, Yarn and pnpm also keep a global cache: npm cache clean --force, yarn cache clean, pnpm store prune.

Questions

Will deleting node_modules break my project?

No. Run npm install (or your package manager) and it is rebuilt from package.json and the lock file.

Let the raccoon do it, safely

Junk Raccoon finds this clutter for you, shows every file first, and keeps a one-click way back. Free beta for Mac.

Download for Mac

Updated 2026-11-20