Quick answer
Yes, node_modules is safe to delete. It only contains packages installed from package.json and your lockfile; npm install, pnpm install or yarn recreates it exactly.
Rebuild with npm ci # or: pnpm install / yarn install
What is it?
node_modules is where npm, pnpm and Yarn install a project's dependencies, including every transitive dependency and platform-specific binary.
Why does it get so big?
- Hundreds of transitive packages per framework
- Precompiled binaries for tools like esbuild, SWC and Sharp
- A separate full copy in every project with npm and Yarn Classic
- Duplicate versions when dependency ranges conflict
How to clean it from the command line
Review what a command matches before you run anything with rm -rf. These deletions are permanent.
What not to delete
- package.json and your lockfile (package-lock.json, pnpm-lock.yaml, yarn.lock)
- Global installs (npm install -g) in your Node installation
- Apps that bundle their own node_modules
How Gigaflush handles Node.js
Gigaflush lists node_modules only when package.json sits right beside it, shows each folder's size, preselects nothing, and re-checks the folder immediately before deleting it. Symlinks and parent-directory paths are refused.
FAQ
Is it safe to delete node_modules?
Yes. It's generated from package.json and your lockfile. Run npm ci, pnpm install or yarn install to get it back. Anything you edited inside node_modules by hand is lost.
Will deleting node_modules break my project?
Only until you reinstall. Commands like npm run dev fail until dependencies are installed again.
Does deleting node_modules free disk space with pnpm?
Less than the folder size suggests. pnpm hard-links files from a shared store, so the store still holds them. Run pnpm store prune to remove unreferenced packages.
How do I delete node_modules in all subfolders?
Use find with -prune on macOS and Linux, Get-ChildItem in PowerShell, or a tool like Gigaflush or npkill that lists them first.