How to find and delete old node_modules on Mac
Each node_modules weighs between 300 MB and 3 GB. With 20 local repos you easily carry 10β20 GB of dependencies you can reinstall with npm install. Git worktrees make it worse: each one has its own copy.
Find them all
Replace ~/workspace with the folder where you keep your projects:
find ~/workspace -name node_modules -type d -prune -exec du -sh {} + 2>/dev/null | sort -rh | head -20Only delete the ones from inactive projects
Regenerates, with a costA good rule: if a project hasn't changed in more than 90 days, its node_modules is a candidate. Don't delete the one for the project you're working on right now: you'll just wait for the reinstall.
To delete one:
rm -rf ~/workspace/old-project/node_modulesInteractive tool
npkill lists all your node_modules and lets you delete them with the space bar:
npx npkill -d ~/workspaceDon't forget build artifacts
Safe.next, dist, build, .turbo, target and .venv also regenerate. In Next.js projects, the .next folder can reach several GB.
FAQ
Do I lose anything if I delete node_modules?
No, as long as you have package.json and the lockfile. It reinstalls exactly the same with npm install, pnpm install or yarn.
Does pnpm save space?
Yes: pnpm stores each package once in a global store and links it into every project. But that store grows too; clean it with pnpm store prune.
Keep reading
How to clear the npm, pnpm, yarn and Homebrew caches
Package managers never clean their own cache. These commands reclaim 2 to 15 GB on a developer Mac.
How to free up space from Xcode and iOS simulators
DerivedData, simulators, iOS runtimes and DeviceSupport can take 20β90 GB. What to delete and how to do it right.
Free up Android Studio space without breaking Expo or React Native
The Android SDK, emulators and Gradle can take 20β40 GB. What you can delete and what Expo needs to keep working.