How to Find and Delete node_modules Safely on Mac
Software developers working on JavaScript and TypeScript apps frequently have dozens of archived or dormant repositories. Each project consumes 300 MB to 2 GB of dependencies, causing massive disk consumption and APFS inode fragmentation. Here is how to clean them safely.
Why node_modules hurts macOS performance
The problem isn't just raw storage in gigabytes — it's file count (inodes). A single medium-sized React or Next.js app can contain 40,000+ tiny files in node_modules.
- Slows down Apple Spotlight indexing
- Inflates Time Machine backup snapshots
- Takes minutes to delete via Finder GUI without crashing
Step 1: Find all node_modules and calculate their sizes
Navigate to your primary developer directory (e.g., ~/Developer or ~/Projects) and run:
find . -name "node_modules" -type d -prune -exec du -sh + | sort -hr | head -20This outputs the 20 largest dependency folders ranked by disk footprint.
Step 2: Delete dormant node_modules folders
If you have dozens of projects, you can delete them in one sweep using Terminal:
find . -name "node_modules" -type d -prune -exec rm -rf '' +⚠️ Warning: Naive Terminal deletion removes dependencies from active projects you are working on right now, requiring a slow reinstall next time you run tests or dev servers.
Step 3: Clean global package manager caches
Package managers maintain redundant global tarball caches in your home directory:
npm:
npm cache clean --forceyarn:
yarn cache cleanpnpm:
pnpm store prunebun:
bun pm cache rmThe safe automated way: SpaceWise Dormant Project Pruner
SpaceWise solves the danger of accidental deletion by introducing intelligent safety heuristics:
- Git Activity Check: Checks git commit timestamps — only flags projects inactive for 30+ days.
- Lockfile Guard: Confirms a valid
package-lock.json,pnpm-lock.yaml, oryarn.lockexists before suggesting cleanup, ensuring 100% reproducible reinstalls. - Build Artifact Clean: Cleans
.next,dist,target, andoutalongside dependencies. - Zero Cloud: Runs completely locally without scanning or uploading your code.
Do all of this in SpaceWise — for free
SpaceWise scans and safely cleans everything covered in this guide with one click. No Terminal required.
Download for Mac FreeRelated Guides
How to Free Up Docker Disk Space on Mac
Prune dangling images, BuildKit layers, and unused volumes safely.
How to Clean Xcode DerivedData on Mac
Reclaim 20–80 GB from Xcode build caches and unused simulator runtimes.
How to Delete Abandoned Ollama & Hugging Face Models
Purge stale local AI model weights eating your SSD.