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.
Fixes npm ERR! Error: EPERM: operation not permitted, rename 'node_modules\.staging'
rm -rf node_modules/.staging 2>/dev/null || truerm -rf node_modules/.staging 2>/dev/null || truenpm ERR! Error: EPERM: operation not permitted, rename 'node_modules\.staging'
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.
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.
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.