How to find and delete old node_modules folders on Mac
In short
node_modules only holds downloaded packages: npm install (or pnpm, yarn, bun) rebuilds it from the lockfile. Deleting it in projects you haven't touched for a while is safe and often frees tens of gigabytes. The same goes for Python's .venv, Rust's target and build folders like .next.
Why it's safe to delete
node_modules is a copy of the packages listed in package.json. Your code isn't there. If the project has a lockfile (package-lock.json, pnpm-lock.yaml, yarn.lock or bun.lock), installing again brings back exactly the same versions:
npm ci # or: pnpm install, yarn install, bun installThe cost is time and a download the next time you open the project. That's why it makes sense for projects you haven't touched in weeks, not for the one you're working on today.
Find them all, with their size
Run this from the folder where you keep your code (here ~/Code; change it to yours). It lists every node_modules with its size, the biggest last, without going into the nested ones:
find ~/Code -type d -name node_modules -prune -exec du -sh {} + 2>/dev/null | sort -hIf you prefer a list where you pick, npx npkill does the same from the current folder and deletes the one you select with the space bar.
Delete them
Inside the project:
rm -rf node_modulesWith pnpm, files in node_modules are links to its shared store, so deleting them frees little by itself. Run pnpm store prune afterwards to remove the packages no project uses any more.
The same idea in other languages
- Python:
.venvorvenv. Comes back withuv syncorpip install -r requirements.txt. - Rust:
target, often several GB.cargo cleandeletes it; the next build recreates it. - Build output:
.next,.nuxt,.turbo,.svelte-kit,.parcel-cache, Swift's.build. They're rebuilt on the next run. - Xcode keeps builds outside the project, in DerivedData (see the Xcode guide).
When to be careful
- No lockfile: installing again may bring newer versions that behave differently.
- Old projects may need the Node version they used (look for
.nvmrcorenginesinpackage.json), especially if they have native modules. - Private packages: you'll need access to that registry (and maybe a VPN) to install them again.
- Edited files inside node_modules are lost. If you patched a package, keep the patch with
patch-packageor your package manager's patch command.
DiskSpace AI does this for you
It analyzes your Mac in minutes, tells you what each folder is and only selects what recreates itself. Your files are kept 7 days in case you change your mind. Free during the beta.
Download the BetaFolders in this guide
- npm cache
~/.npm/_cacacheRecreates itself - npx temporary packages
~/.npm/_npxRecreates itself - pnpm store
~/Library/pnpm/storeRecreates itself - Yarn cache
~/Library/Caches/YarnRecreates itself - Bun cache
~/.bun/install/cacheRecreates itself - uv cache (Python)
~/.cache/uvRecreates itself - Global npm packages
~/.npm-globalReview
More guides
- Not enough space to update macOS? How to make room safely
- What is “System Data” on a Mac, and why is it so big?
- How to free up space on your Mac without deleting anything important
- How to find and delete duplicate photos on Mac
- Docker taking up too much space on Mac? How to shrink Docker.raw
- Xcode taking up space? What you can delete (and what you can't)
- How to clear npm, pnpm, pip, uv and Homebrew caches on Mac
- How to find large files on Mac (including hidden ones)
- What is purgeable space on Mac, and how to free it
- DaisyDisk alternative: DiskSpace AI vs DaisyDisk
- CleanMyMac alternative without a subscription
- The best disk space analyzers for Mac in 2026
- AI models filling your Mac? Where Ollama, LM Studio and Hugging Face keep them
- iPhone backups taking space on your Mac? How to find and delete them
- Is it safe to delete ~/Library/Caches on Mac?