Limpa Tudo

Guides

How to delete all node_modules without breaking Electron apps and extensions

Published November 23, 2026

Every JavaScript project has its own node_modules, and idle projects keep taking hundreds of MB each. Deleting them is safe — npm install brings everything back — but the command that gets passed around has a trap.

1. Measure first, only where your projects live

find ~/projects -name node_modules -type d -prune -exec du -sh {} + | sort -h

Replace ~/projects with the folder where you keep code. -prune stops find from descending into nested node_modules (already counted in the top one).

2. The trap: don't run it on your whole home folder

A find ~ -name node_modules -exec rm -rf also finds node_modules that aren't projects:

Deleting those breaks the extension or tool until you reinstall it. That's why the first step is limiting the search to your projects folder.

3. Delete only idle projects

To catch only projects untouched for more than 30 days:

find ~/projects -name node_modules -type d -prune -mtime +30 -print
# checked the list? then:
find ~/projects -name node_modules -type d -prune -mtime +30 -exec rm -rf {} +
For a project you'll come back to, use npm ci afterwards: it reinstalls exactly what's in package-lock.json.

4. Don't forget the global caches

Besides each project, package managers keep downloaded packages:

npm cache clean --force   # ~/.npm
pnpm store prune          # pnpm global store
yarn cache clean          # Yarn cache

5. Other project folders that grow

.next, dist, build, .venv and target (Rust) follow the same logic: they're generated and come back on the next build. Watch out for build/ and dist/ folders that some projects commit to git.

In Limpa Tudo, the search for node_modules, .next, .venv and the like is limited to your configured project folders, only looks where there's a package.json (or equivalent) next to it, and never offers a build/ folder tracked by git. Each folder is shown with the project name, size and path.