How to fix npm ERR! Error: EPERM: operation not permitted, rename 'node_modules\.staging' in npm
Rename of .staging failed due to locks or protected paths. Close locking apps (VS Code/IDEs), whitelist the path in Defender/AV, or move the project to a user-writable filesystem.
Quick fix
Fixes npm ERR! Error: EPERM: operation not permitted, rename 'node_modules\.staging'
rm -rf node_modules/.staging 2>/dev/null || true- Remove locks and stale staging
- Whitelist or relocate the project
- Prefer WSL2 Linux filesystem
- Retry with a clean install
rm -rf node_modules/.staging 2>/dev/null || truenpm ERR! Error: EPERM: operation not permitted, rename 'node_modules\.staging'
What this error means
npm stages installs in node_modules/.staging before moving files into place. On Windows/WSL or network/synced drives, file locks from Defender/AV/IDEs or filesystem restrictions can block the rename and throw EPERM. WSL2 on Windows-mounted paths (mntc) often hits this.
Typical symptoms
- EPERM rename node_modules/.staging during npm install
- More frequent on Windows/WSL or synced/network folders (OneDrive/Dropbox)
- Install succeeds when Defender/AV is disabled or path is moved
- Install succeeds after closing VS Code/IDEs/watchers
Common causes
- Windows Defender/AV/EDR locking files in node_modules/.staging
- Project on protected/synced folders (OneDrive, Dropbox, corporate shares)
- WSL2 using Windows-mounted paths with metadata/symlink issues
- Editors/IDEs (VS Code) or watchers holding file handles
- Stale partial installs leaving inconsistent staging state
How to fix "npm ERR! Error: EPERM: operation not permitted, rename 'node_modules\.staging'"
rm -rf node_modules/.staging 2>/dev/null || trueClose VS Code/IDEs and stop watchers before retrying.
Add node_modules to Windows Defender/AV exclusions. Prefer a user-owned local path (e.g., C:/dev or ~/projects). Avoid OneDrive/Dropbox/network shares for installs.
If on WSL2, work inside /home (Linux filesystem) instead of /mnt/c to avoid NTFS rename restrictions.
npm cache clean --force
npm installAs a temporary workaround, use npm install --no-optional if an optional dep is causing repeated staging churn.
Advanced notes
Keeping projects out of protected/synced folders avoids most EPERM rename issues. Defender/AV exclusions for node_modules speed installs and prevent locks. In CI/Docker, ensure the working directory is on a writable volume and not shared with conflicting processes.
Frequently asked questions
- What does "npm ERR! Error: EPERM: operation not permitted, rename 'node_modules\." mean?
- staging before moving files into place. On Windows/WSL or network/synced drives, file locks from Defender/AV/IDEs or filesystem restrictions can block the rename and throw EPERM. WSL2 on Windows-mounted paths (mntc) often hits this.
- How do I fix "npm ERR! Error: EPERM: operation not permitted, rename 'node_modules\."?
- Rename of .staging failed due to locks or protected paths. Close locking apps (VS Code/IDEs), whitelist the path in Defender/AV, or move the project to a user-writable filesystem.
- What causes "npm ERR! Error: EPERM: operation not permitted, rename 'node_modules\."?
- Windows Defender/AV/EDR locking files in node_modules/.staging Project on protected/synced folders (OneDrive, Dropbox, corporate shares) WSL2 using Windows-mounted paths with metadata/symlink issues
- Is the "npm ERR! Error: EPERM: operation not permitted, rename 'node_modules\." error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐npm Docs: folders and permissions(Official Docs)
- ๐ฌStack Overflow: rename error during npm install(Stack Overflow)
- ๐npm/npm#16845 - rename errors(GitHub)