How to fix npm ERR! Error: EPERM: operation not permitted, rename 'node_modules\.staging' in npm

npmINTERMEDIATEMEDIUMUpdated Dec 2, 2025ยท 259 views

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
  1. Remove locks and stale staging
  2. Whitelist or relocate the project
  3. Prefer WSL2 Linux filesystem
  4. Retry with a clean install
npm โ€” error
rm -rf node_modules/.staging 2>/dev/null || true
npm 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

  1. Windows Defender/AV/EDR locking files in node_modules/.staging
  2. Project on protected/synced folders (OneDrive, Dropbox, corporate shares)
  3. WSL2 using Windows-mounted paths with metadata/symlink issues
  4. Editors/IDEs (VS Code) or watchers holding file handles
  5. Stale partial installs leaving inconsistent staging state

How to fix "npm ERR! Error: EPERM: operation not permitted, rename 'node_modules\.staging'"

1Remove locks and stale staging
bash
rm -rf node_modules/.staging 2>/dev/null || true

Close VS Code/IDEs and stop watchers before retrying.

2Whitelist or relocate the project

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.

3Prefer WSL2 Linux filesystem

If on WSL2, work inside /home (Linux filesystem) instead of /mnt/c to avoid NTFS rename restrictions.

4Retry with a clean install
bash
npm cache clean --force
npm install
5Optional: skip optional deps if they trigger staging issues

As 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