Is It Safe to Delete node_modules on Your Mac?

Yes, but read this firstDiskmack safety tier: Caution
**/node_modules

Yes, it's safe to delete node_modules, with one condition: keep the project's package.json and lockfile, because those two files rebuild the folder with a single install command. Nothing inside node_modules is unique to you; the package manager can download all of it again. The real judgment call is which projects to hit. Dead side projects are free space; active ones just cost you a reinstall.

What it is

node_modules is the folder where a JavaScript package manager (npm, yarn, pnpm, or bun) installs a project's dependencies. Every library the project imports lives there, along with every library those libraries need in turn. You never edit it by hand. The package manager owns it completely and can reconstruct it at any time from package.json and the lockfile sitting next to it.

It gets huge because dependencies have dependencies. Installing one web framework can pull in hundreds of small packages, each shipping its own docs, tests, and sometimes prebuilt binaries. And since every project gets its own private copy (pnpm being the main exception), ten projects means ten separate piles. A Mac used for JavaScript work for a year or two often carries dozens of node_modules folders adding up to tens of gigabytes, most belonging to projects nobody has opened in months.

Is it safe to delete?

Deleting node_modules destroys nothing unique. It holds no source code of yours, no settings, no data. The caution label exists because the folder belongs to a specific project: delete it from something you work on daily and that project will not build or run until you reinstall, which takes a few minutes and a network connection.

So sort by project, not by folder. Abandoned experiments, finished tutorials, repos you cloned to read once: delete their node_modules without hesitation. For projects you still touch, decide whether the reclaimed space is worth a reinstall next time you open them. Diskmack finds every node_modules folder on your Mac automatically and cleans them the safe way.

How to check its size

In Finder: In Finder, choose Go > Go to Folder (or press Command-Shift-G), paste the path to the project's copy, for example ~/Projects/my-app/node_modules, and press Return. Select the folder and press Command-I; the Get Info window shows the size once it finishes counting.

In Terminal:

du -sh ~/Projects/my-app/node_modules

Swap in your project's real path; if it contains spaces, type du -sh followed by a space, then drag the node_modules folder from Finder into the Terminal window and it fills in the escaped path for you. To size every copy under your home folder at once, run: find ~ -name node_modules -type d -prune -exec du -sh {} + 2>/dev/null.

How to clean it

  1. Stop anything using the project: quit dev servers, file watchers, and any terminal still running npm scripts in it.
  2. Confirm the project still has its package.json and a lockfile (package-lock.json, yarn.lock, pnpm-lock.yaml, bun.lock, or the older bun.lockb). Those files are the recipe that rebuilds the folder.
  3. In Finder, open the project folder and drag node_modules to the Trash.
  4. Repeat for other projects, starting with the oldest and most forgotten. Those are pure reclaimed space.
  5. Empty the Trash to actually free the disk space.
  6. Next time you return to one of these projects, run npm install (or yarn, pnpm, or bun install) inside it and the folder comes back.

If a project uses pnpm, its node_modules is mostly hard links into the shared store at ~/Library/pnpm/store, so deleting it frees far less space than the size Finder reports.

Will it come back?

Only if you ask it to. node_modules regenerates the moment you run npm, yarn, pnpm, or bun install in that project, and it returns at roughly full size, because the project needs the same packages it needed before. That is a rebuild, not a leak. What creeps upward over time is the number of projects: every new clone and every quick experiment leaves another copy behind after you lose interest. The durable fix is an occasional sweep of dead projects, not repeatedly deleting the folder out of a project you use every day.

Common questions

Will deleting node_modules break my project?

No. As long as the project keeps its package.json (and ideally a lockfile such as package-lock.json, yarn.lock, pnpm-lock.yaml, or bun.lock), one install command restores everything exactly as it was. The only real cost is time: large projects can take several minutes to reinstall.

How big is node_modules usually?

It varies wildly. A small script's folder might be a few tens of megabytes, a modern web app often lands in the hundreds of megabytes, and monorepos can pass a gigabyte. The total across a busy Mac is what hurts: dozens of forgotten copies add up fast.

Is there a command that finds every node_modules folder on my Mac?

Yes. Run find ~ -name node_modules -type d -prune -exec du -sh {} + 2>/dev/null in Terminal. It lists each copy with its size and skips descending inside them, though it can still take a while on a full disk.

Should I delete node_modules before backing up or archiving a project?

Yes. It is the textbook folder to exclude: huge, fully regenerable, and slow to copy, so it drags down Time Machine and cloud sync. Keep package.json and the lockfile in the archive and you can rebuild the folder on any machine.

Related folders