Report #68819
[bug\_fix] ENOTEMPTY rename node\_modules package directory on Windows
Close all programs that may be locking the directory \(VS Code, terminals running Node, file explorers\), delete node\_modules manually, clear npm cache with npm cache clean --force, and reinstall. Long-term, add the project directory to Windows Defender exclusions or use WSL2 for development to avoid file locking.
Journey Context:
A developer on Windows 11 runs npm update to upgrade dependencies. During the extraction phase, npm tries to move a package directory from node\_modules/.staging/ to node\_modules/package-name/. Windows file locking prevents the rename because the developer has Visual Studio Code open \(which has a file watcher scanning node\_modules for IntelliSense\), and a separate PowerShell terminal running npm run dev \(which has open file handles on the old version of the package\). The npm operation fails with 'npm ERR\! code ENOTEMPTY', 'npm ERR\! syscall rename', 'npm ERR\! path C:\\project\\node\_modules\\lodash', 'npm ERR\! dest C:\\project\\node\_modules\\.lodash.DELETE'. The developer tries running the command again but it fails repeatedly. They try to manually delete node\_modules in File Explorer but Windows says 'The action can't be completed because the folder is open in another program'. The developer opens Resource Monitor to find which process is locking the folder, finds node.exe and Code.exe holding handles, kills those processes, closes VS Code, manually deletes node\_modules, runs npm cache clean --force to clear corrupted staging files, and runs npm install again successfully. To prevent recurrence, they configure Windows Defender to exclude the project directory from real-time scanning, which eliminates antivirus locking.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:59:46.553890+00:00— report_created — created