Deleting node_modules on Windows takes forever. Here's why, and how to fix it

Why Explorer crawls deleting node_modules on Windows (tiny files, Defender, Recycle Bin, long paths) and faster fixes: rd, rimraf, robocopy and Dev Drive.

Nov 1, 20262 min read

Back lane: Explorer, one file at a time through the scanner into the Recycle BinFront lane: rd /s /q, the whole tray at onceThe same twenty files, deleted two ways. Explorer enumerates each one, waits for the scan, and moves it to the Recycle Bin; rd /s /q unlinks them directly. The timings are illustrative: on a real node_modules there are tens of thousands of files, so the per-file cost is what you feel.

Right-click → Delete on a node_modules folder in Windows Explorer, and you can watch the “Calculating…” dialog for minutes. On macOS the same folder disappears in seconds. Here’s what’s going on, and how to make it fast.

Why it’s slow

  • Lots of small files. A typical node_modules holds tens of thousands of files. On NTFS, per-file overhead dominates, and deletion is about the file count far more than the gigabytes.
  • Explorer does extra work. It enumerates everything first to show progress and (unless you hold Shift) moves the whole tree to the Recycle Bin, which is far slower than deleting.
  • Real-time antivirus. Microsoft Defender inspects file operations, and with this many files the overhead is noticeable.
  • Long paths. Deeply nested dependencies can exceed the legacy 260-character MAX_PATH limit, which makes some tools fail halfway with “path too long”.

Faster ways to delete

rd /s /q node_modules

Skips the Recycle Bin and the progress dialog. Usually much faster than Explorer.

Fix long paths once

Windows 10 and 11 can lift the 260-character limit for apps that support it. Enable it with Group Policy (Computer Configuration → Administrative Templates → System → Filesystem → Enable Win32 long paths) or this registry value, from an elevated PowerShell:

New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
  -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force

Git has its own switch: git config --system core.longpaths true.

Make the problem smaller: Dev Drive

Windows 11 supports a Dev Drive: a volume formatted with ReFS and tuned for development workloads, where Defender can run in a performance mode that defers scans. Putting your repositories (and package caches) on a Dev Drive speeds up installs, builds and deletions. Set it up in Settings → System → Storage → Advanced storage settings → Disks & volumes → Create Dev Drive.

Don’t delete them one by one

Most people asking this question don’t have one node_modules to delete. They have thirty. To clear them all from the command line, see how to delete all node_modules folders (it has PowerShell and cmd versions).

Or use Gigaflush for Windows. It sits in the system tray, scans your projects folder for node_modules and other build folders (Rust, Flutter, Python, Gradle, Maven), shows sizes, and deletes the ones you pick directly, without the Recycle Bin or Explorer’s progress dialog, with live progress per folder.

Keep reading