DEV Community

Asad Rajput
Asad Rajput

Posted on Originally published at sweepdevv.netlify.app

How to delete node_modules on Windows (safely, and for good)

If you've cloned more than a handful of JavaScript projects, there's a good chance tens of gigabytes of your drive are sitting inside folders named node_modules — most of which you'll never open again. Here's how to find them, delete them safely, and avoid the errors that make this more annoying than it should be on Windows.

Is it safe to delete node_modules?

Yes, in almost every case. node_modules holds your project's installed dependencies, not your own code. Run npm install (or yarn / pnpm install) again and it rebuilds from your package.json and lockfile. The only time to pause is if you've manually edited a file inside node_modules directly — rare, and usually a sign something else is wrong with the project anyway.

Method 1: File Explorer

The obvious way — right-click the folder, choose Delete. It works, but it's slow on large dependency trees (some packages nest hundreds of small files), and it's the method most likely to hit the error in the next section.

Method 2: Command Prompt

Faster than Explorer, and handles deeply nested folders better:

cd path\to\your\project
rmdir /s /q node_modules
Enter fullscreen mode Exit fullscreen mode

/s removes all subfolders and files; /q skips the "are you sure" prompts.

Method 3: PowerShell

Remove-Item -Recurse -Force .\node_modules
Enter fullscreen mode Exit fullscreen mode

Functionally similar to the Command Prompt method. Use whichever terminal you already have open.

Getting a "path too long" or "access denied" error? Windows historically capped file paths at 260 characters, and deeply nested node_modules folders (packages inside packages inside packages) blow past that easily. Two fixes: enable long path support by opening Group Policy Editor → Computer Configuration → Administrative Templates → System → Filesystem → "Enable Win32 long paths", or, faster, use robocopy to overwrite the folder with an empty one first: robocopy empty_folder node_modules /mir, then delete the now-empty result.

Method 4: npkill (finds every node_modules on your drive)

If you have dozens of old projects scattered across your drive, hunting each one down manually isn't realistic. npkill is a free command-line tool that scans your drive, lists every node_modules folder with its size, and lets you delete the ones you don't need interactively:

npx npkill
Enter fullscreen mode Exit fullscreen mode

What about Docker, WSL, and everything else?

node_modules is usually just the beginning. Docker Desktop's virtual disk, WSL2's disk image, and build caches from tools like Webpack or Vite tend to grow quietly in the background too — and none of them show up clearly in Windows' own storage view.


I'm exploring building a small tool that finds all of this in one scan — node_modules, Docker images, WSL bloat, build caches — classified as safe or not, cleared in a few clicks. Still early stage: sweepdevv.netlify.app

Top comments (0)