Folder

Is node_modules safe to delete on a Mac?

Yes, node_modules is safe to delete in your own projects: it is rebuilt from package.json and the lockfile, and npm ci deletes it by itself before every install.

1 safe2 careful1 never

updated read 3 minfor npm, pnpm, Yarn and Bun projects on macOS

The short answer

  1. 01

    Safe to delete in your own projects. node_modules holds installed dependencies, rebuilt from package.json and the lockfile.

  2. 02

    Your package manager writes it on every install: npm, pnpm, Yarn or Bun, one folder per project.

  3. 03

    You lose nothing permanent as long as the lockfile is there. The project will not run until you install again.

  4. 04

    The command: rm -rf node_modules in the project, then npm ci, pnpm install, yarn install or bun install.

  5. 05

    Leave node_modules inside installed apps alone. Some apps ship their own and need them to run.

See its real size on your Mac. Hoardless measures this folder and previews the delete.Download free trial

What is the node_modules folder?

node_modules is a JavaScript project's installed dependencies, written next to package.json by npm, pnpm, Yarn or Bun. It holds every package the project needs plus everything those packages need, so it is often much larger than the project's own code.

It is output, not source. The list of what goes in it lives in package.json, and the exact versions live in the lockfile (package-lock.json, pnpm-lock.yaml, yarn.lock or bun.lock).

What writes it and why does it grow?

Every install writes it. Each project keeps its own copy, so ten projects with similar dependencies mean ten node_modules folders.

  • One per project, forever: a project you stopped working on keeps its node_modules until you delete it.
  • Nested projects: monorepos and example folders can each have their own node_modules.
  • Different storage per tool: npm and Yarn 1 copy files in. pnpm hard-links them from its store, and Bun on macOS uses copy-on-write clones, so part of the space may be shared with a cache.

How big does node_modules get?

It depends on the project's dependency tree, so there is no normal size. Measure your own:

du -sh node_modules

Run inside a project. Prints its size. Removes nothing.

find ~ -name node_modules -type d -prune -exec du -sh {} +

Lists every top-level node_modules under your home with its size. -prune skips the nested ones inside. Removes nothing and can be slow on a large home folder.

Is it safe to delete node_modules?

npm treats it as disposable itself: its docs say that if node_modules is already present, npm ci removes it automatically before it installs.

WhatVerdictWhat you lose
node_modules in an old project with a lockfileSafeInstalled dependencies. Reinstall from the lockfile.
node_modules in a project with no lockfileCarefulThe exact versions. A reinstall may resolve newer ones.
node_modules you edited by hand (patches)CarefulYour edits, unless they are saved with a tool such as patch-package.
node_modules inside an installed appNeverThe app can stop working. Only delete folders in your own project directories.

How do I delete node_modules?

In one project, delete it and reinstall when you need it:

rm -rf node_modules

Run inside the project. Deletes its dependencies permanently, without the Trash.

npm ci

Reinstalls exactly what package-lock.json lists. npm's docs say it needs a package-lock.json or npm-shrinkwrap.json. Use pnpm install, yarn install or bun install for those tools.

The manual way: in Finder, open the project folder, drag node_modules to the Trash, then empty the Trash when you are sure. For many projects at once, npkill (npx npkill) lists node_modules folders with sizes and deletes the ones you pick.

What Hoardless does: its Unused view lists node_modules only in git repositories with no commit and no local git activity in 90 days, where no working file changed in 90 days, the folder itself was untouched for 90 days, git ignores it, and it is at least 20 MB. Folders outside a git repo are never listed. Selected folders go to the Trash at the Confirm tier, logged in the undo log.

What comes back and when?

It comes back the moment you install. Running the project's install command rebuilds node_modules from the lockfile. If the npm, pnpm, Yarn or Bun cache still holds those packages, the reinstall is fast and mostly offline.

Projects you never reinstall stay small for good. To clear the shared caches as well, see the npm cache and pnpm store pages.

Find node_modules in projects you stopped using

Hoardless's Unused view checks git history and file dates, lists node_modules in repos idle for 90 days, and moves the ones you pick to the Trash (Confirm tier) with an undo log. Active projects and tracked folders are never listed.

14-day full trial. macOS 14 or later.

Questions

Will deleting node_modules break my project?

Only until you reinstall. Keep package.json and the lockfile, then run your package manager's install command and the folder comes back.

Is it safe to delete node_modules without a lockfile?

It is safe to delete, but a reinstall may pick newer versions than you had. Commit or keep the lockfile first if you want the same versions.

How do I find every node_modules folder on my Mac?

Run find ~ -name node_modules -type d -prune -exec du -sh {} + to list each top-level node_modules with its size. It removes nothing and can take a while.

Should I delete node_modules in a project I still use?

Only if you want a clean reinstall. Deleting it frees space for the moment, but the next install writes it back.

Does deleting node_modules clear the npm cache?

No. The npm cache in ~/.npm/_cacache is separate. Reinstalls are faster while that cache is still there.