Diskzyv0.1
Safe to delete

What is node_modules on Mac, and is it safe to delete?

Short answer

Yes, node_modules is safe to delete. It contains only downloaded dependencies, and running your package manager's install command in the project recreates it.

Where it is

<project>/node_modules

What it is

When you run npm install, yarn or pnpm install in a JavaScript or TypeScript project, the package manager reads package.json and puts every dependency, and every dependency of those dependencies, into a node_modules folder inside the project.

It gets large because modern projects pull in hundreds or thousands of packages, some with compiled binaries. Each project has its own copy, so ten projects mean ten node_modules folders, including projects you have not opened in years.

Nothing you wrote lives in node_modules. Your code, package.json and the lockfile are what matter, and they are enough to rebuild it.

How big it gets

Commonly hundreds of MB per project, and over a GB for larger apps and monorepos.

How to clear it by hand

  1. Stop any dev server or build that is running in the project.
  2. Open Terminal and change into the project folder.
  3. Run the command below. It deletes the node_modules folder in the current folder only, so check where you are with pwd first.
  4. When you work on the project again, run npm install, yarn install or pnpm install to restore it.
In Terminal
rm -rf node_modules

What happens afterwards

The project will not run or build until you install dependencies again. With a lockfile in place you get the same versions back, and the reinstall is quicker if the package manager's cache is still on disk.

How Diskzy handles it

Diskzy finds project build folders such as node_modules in the Clean up tab. A folder is left unticked if its project changed in the last 14 days.

Related 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日本語