# Is it safe to delete node_modules?

Is it safe to delete? · Project folders · Updated 21 November 2026. By Mohit Nippanikar, who makes SiftMac.

## The short answer

- **Yes**, in projects you aren’t running right now. It’s the packages your package manager installed from `package.json`; none of your own code is in it.
- **What it costs you:** one install before that project runs again, which downloads or copies every package back.
- **Does it come back?** Yes, the same tree as before, when you run `npm install` (or `yarn`, `pnpm install`, `bun install`) against the project’s lockfile.
- SiftMac’s verdict: Rebuilds

## 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.

- The lockfile (`package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, or `bun.lock`) records the exact version of every package, so a reinstall gives you the same tree.
- Some packages run setup scripts or compile native code while installing. Those steps run again when you reinstall.
- With npm, every project holds its own full copy of every package, so ten finished projects built on the same framework hold that framework ten times. pnpm and Bun share files between projects instead.

## 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

- Until you reinstall, `npm run dev`, `npm test` and the like fail with missing-module errors, and your editor marks imports in red. That’s expected.
- The reinstall takes about as long as the first install of a fresh clone. It reuses the package manager’s cache where it can, see [npm’s cache](https://siftmac.com/safe-to-delete/npm-cache), and downloads the rest.
- Native modules are compiled again, so the build tools they needed the first time must still be on your Mac.
- Your source, `package.json`, the lockfile, Git history and `.env` files aren’t touched.

## 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](https://siftmac.com/safe-to-delete/nextjs-cache) that rebuilds the same way, and each package manager keeps a cache outside your projects: [npm](https://siftmac.com/safe-to-delete/npm-cache), [pnpm](https://siftmac.com/safe-to-delete/pnpm-store), [Yarn](https://siftmac.com/safe-to-delete/yarn-cache) and [Bun](https://siftmac.com/safe-to-delete/bun-cache).

## 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: https://siftmac.com/SiftMac.dmg (scanning is free, and so is the first 2 GB of cleaning).

## Sources

- [npm Docs: npm ci](https://docs.npmjs.com/cli/v11/commands/npm-ci)
- [npm Docs: folders used by npm](https://docs.npmjs.com/cli/v11/configuring-npm/folders)

## Related

- [Is it safe to delete ~/.npm, npm’s cache?](https://siftmac.com/safe-to-delete/npm-cache)
- [Is it safe to delete pnpm’s store?](https://siftmac.com/safe-to-delete/pnpm-store)
- [Is it safe to delete a Next.js project’s .next folder?](https://siftmac.com/safe-to-delete/nextjs-cache)
- [Xcode DerivedData, node_modules and Docker: what’s safe to delete on a developer’s Mac](https://siftmac.com/guides/developer-files-on-mac)
- [What fills a web developer’s Mac, from node_modules to Docker](https://siftmac.com/for/web-developers)

Canonical: https://siftmac.com/safe-to-delete/node-modules
