SiftMac
Is it safe to delete? · Project folders · Updated 21 November 2026

Is it safe to delete node_modules?

By Mohit Nippanikar, who makes SiftMac

The short answer
On this page
  1. What node_modules is
  2. Where they are
  3. How big they get
  4. How to delete it safely
  5. What happens afterwards
  6. Where to keep it
  7. Questions

1. What node_modules is

When you run npm install in a JavaScript or TypeScript project, npm reads package.json, works out the full tree of dependencies and their dependencies, and puts all of them into a node_modules folder at the project root. Yarn, pnpm and Bun do the same job with their own layouts. You never write anything in it by hand: it’s produced from two small files you keep, package.json and the lockfile.

2. Where they are

One sits next to each package.json you’ve installed, usually at the top of the project:

~/Projects/my-app/node_modules

Monorepos and workspaces can have one at the top and more inside each package. To list every one under your code folder with its size, biggest last (change ~/Projects to wherever your code lives):

find ~/Projects -type d -name node_modules -prune -print0 | xargs -0 du -sh | sort -h

3. How big they get

Size follows the dependency tree, not your code. A project with a framework, a bundler, a test runner and type definitions pulls in far more files than its own source, and old projects you never open again keep all of it. For one project:

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

In pnpm and Bun projects on a Mac, that number overstates what deleting gets back. Their files are clones of a shared store, and the blocks they share stay in use until the store lets go of those packages too.

4. How to delete it safely

  1. Pick projects you aren’t working on today, and stop any dev server, watcher or test run inside them.
  2. Check the lockfile is there, and commit or copy anything you changed. Edits made by hand inside node_modules are lost with it.
  3. Delete the folder in Finder, or in Terminal by its full path.
rm -rf ~/Projects/old-app/node_modules

When you return to the project, install from the lockfile. npm ci is the strict way: it needs a lockfile that matches package.json, never rewrites either file, and removes any node_modules already there before it installs.

cd ~/Projects/old-app
npm ci

5. What happens afterwards

6. Where to keep it

Leave node_modules alone in the project you’re running right now, and wherever you’ve patched a package in place without saving the change anywhere else. Next.js projects also have a [.next folder](/safe-to-delete/nextjs-cache) that rebuilds the same way, and each package manager keeps a cache outside your projects: npm, pnpm, Yarn and Bun.

Questions

Is it safe to delete node_modules and reinstall?

Yes. It’s the standard fix for a broken install, and npm ci does exactly that on its own: it deletes node_modules, then installs again from the lockfile.

Will deleting node_modules change my package versions?

Not when the project has a lockfile and you install from it. Without one, a reinstall picks the newest versions your package.json ranges allow, which may differ from what you had.

Why does deleting node_modules free so little in a pnpm project?

Its files are clones of pnpm’s store, so the store still holds those blocks. The space comes back once pnpm store prune drops packages no project uses.

How do I clear node_modules in every old project at once?

List them first with the find command above and read the paths. Then delete the ones in projects you’ve finished with. A blanket delete across all your code also hits the project you open tomorrow, which then needs a reinstall first.

How SiftMac handles it. Its Developer files category lists each node_modules that has a package.json beside it, in projects whose own files haven’t changed for 1, 3 or 6 months (you choose), with the project’s name and when it last changed. None is ticked until you tick it, a folder a running program is using is skipped, and the size shown is what deleting frees, so files pnpm or Bun cloned from their store count only for what they don’t share. Cleared folders are deleted rather than kept on the Undo Shelf, since an install brings them back.

Download SiftMac · scanning is free, and so is your first 2 GB of cleaning · See how it works