Diskzyv0.1

node_modules eating your disk? Find and clear them on Mac

October 10, 2026 · 5 min read

node_modules folders are safe to delete in any project you are not working on right now. They contain only downloaded dependencies, and the install command recreates them. One Terminal command lists every one under your projects folder by size, so you can see which are worth removing.

The package managers also keep download caches outside your projects. Those can be cleared too, with each tool's own command.

Why node_modules takes so much space

With npm and Yarn, each project gets its own complete copy of every dependency, and of everything those dependencies need. A small web app can pull in a very large tree of packages. Ten old projects mean ten separate copies.

The folders are also made of an enormous number of small files, which is why they are slow to copy, slow to back up and slow to index. Nothing in them is yours. The list of what to install is in package.json and the lockfile, and those are what you keep.

List every node_modules folder by size

The command below searches a folder for node_modules directories, measures each one, and sorts the list with the largest last. It only reads. Replace ~/Projects with the folder where you keep your code.

Point it at your code folder, not at your whole home folder. Apps and editors keep node_modules folders of their own inside ~/Library and inside application bundles, and those are part of the app, not leftovers. Deleting them breaks the app.

find ~/Projects -type d -name node_modules -prune -exec du -sh {} + 2>/dev/null | sort -h

Decide which ones to delete

Deleting node_modules costs you only the time of the next install, so the question is which projects you will open soon.

Delete them safely

Stop any dev server or build running in the project first. Then, in Finder, open the project folder and move node_modules to the Trash. That is the forgiving way: if the reinstall fails, you can put the folder back before emptying the Trash.

When you return to the project, run the install command for the package manager it uses, shown below for npm. If the project has a package-lock.json, npm ci installs exactly the versions recorded in it.

Other build output in the same projects can go the same way: folders such as .next, dist, build and .turbo are recreated by the next build.

npm install

Clear the package manager caches

Outside your projects, each package manager keeps a cache of everything it has downloaded, so repeat installs are fast. These caches only grow. The commands below are the documented ways to clear them, and each deletes that tool's download cache only. Your projects keep working, and the next install downloads again.

npm cache clean --force
yarn cache clean
pnpm store prune
bun pm cache rm

Use less space in the first place

pnpm stores each version of a package once on the disk and links it into every project that uses it, so ten projects with the same dependencies take little more than one. If node_modules is a recurring problem, switching new projects to pnpm is the lasting fix.

A side effect is that sizes look wrong. A tool that adds up file sizes counts a linked package once per project, so a pnpm node_modules folder can appear much larger than the space it really uses.

It also helps to keep code out of synced folders. A node_modules folder inside iCloud Drive or Dropbox means a huge number of small files being uploaded for no benefit.

How Diskzy handles node_modules

Diskzy's Clean up tab finds project build folders, including node_modules, .build, Pods and virtual environments, wherever they are on the disk. A folder is left unticked if its project changed in the last 14 days, so the projects you are working on are not touched unless you choose them.

The npm, Yarn, pnpm and Bun caches are listed and ticked. Everything removed goes to the Trash, so a folder can be put back until you empty it.

Common questions

Is it safe to delete node_modules?
Yes, inside your own projects. It holds only downloaded dependencies, and npm install, yarn install or pnpm install recreates it. Do not delete node_modules folders inside apps or inside ~/Library.
How do I find all node_modules folders on my Mac?
Run find with -name node_modules and -prune on the folder where you keep your code, and pass each result to du -sh to see its size. The full command is in this guide.
Will deleting node_modules break my project?
No. The project will not run until you install again, and then it works as before. With a lockfile, the same versions are installed.
Is it safe to clear the npm cache?
Yes. The cache is a local copy of packages npm has already downloaded. npm fetches whatever is missing from the registry on the next install.
Why is my node_modules folder bigger than my whole project?
Because it contains every dependency and everything those dependencies depend on. Your own code is usually a small fraction of the total.

Related guides

Uninstall guides

See where your Mac's space went

Diskzy maps your disk, explains System Data and clears what's safe. Free for 72 hours, then $9 once for 2 Macs.

Try Diskzy for free
Read this in:EnglishEspañolDeutschPortuguêsFrançaisTürkçe日本語