Skip to content
Developer Guide

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.

October 20265 min read

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 -20

This 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 --force

yarn:

yarn cache clean

pnpm:

pnpm store prune

bun:

bun pm cache rm

The 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, or yarn.lock exists before suggesting cleanup, ensuring 100% reproducible reinstalls.
  • Build Artifact Clean: Cleans .next, dist, target, and out alongside 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 Free