How to fix npm ERR! Error: EPERM: operation not permitted, <syscall> '<path>' in npm
Windows/WSL often throws EPERM when npm touches files locked by AV/IDEs or on restricted mounts. Release locks, fix ownership, shorten paths, and re-run npm with user-owned locations.
Quick fix
Fixes npm ERR! Error: EPERM: operation not permitted, <syscall> '<path>'
npm config set cache ~/.npm-cache
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
export PATH="$HOME/.npm-global/bin:$PATH"
rm -rf node_modules package-lock.json
npm cache clean --force- Identify the blocked path and process
- Release locks and AV interference
- Move to a user-owned, POSIX-friendly path
- Use user-owned cache/prefix and clean temp files
npm config set cache ~/.npm-cachemkdir -p ~/.npm-globalnpm config set prefix ~/.npm-globalexport PATH="$HOME/.npm-global/bin:$PATH"rm -rf node_modules package-lock.jsonnpm cache clean --forcenpm ERR! Error: EPERM: operation not permitted, <syscall> '<path>'
What this error means
EPERM indicates the OS blocked the requested filesystem operation even before checking permissions. In npm this happens when Windows/WSL or security tools deny rename/unlink/mkdir on node_modules, or when the path lives on a restricted mount or long path. It is common on Windows with Defender/AV, long paths, or VS Code holding handles; on WSL2 working on /mnt/c (NTFS); and in Docker/CI when the workspace is owned by a different user. Unlike EACCES, EPERM often points to policy or a lock rather than simple UNIX mode bits.
Typical symptoms
- npm install/ci fails with EPERM on rename/unlink/mkdir
- Works from elevated PowerShell/Admin but fails otherwise
- VS Code or a watcher holds node_modules open during install
- Windows Defender/AV logs or popups during npm install
- Long Windows paths (>260 chars) near node_modules
Common causes
- Antivirus/Defender/EDR locking files under node_modules or cache
- Editors (VS Code) or watcher processes holding file handles
- NTFS/SMB mounts (WSL2/network) denying operations
- Long path or read-only attribute on Windows directories
- Docker/CI running npm as a different user than the workspace owner
- Leftover root-owned artifacts from previous sudo installs
How to fix "npm ERR! Error: EPERM: operation not permitted, <syscall> '<path>'"
Copy the path from the error. On Windows, use Resource Monitor or handle.exe <path> to see which process holds it.
Close VS Code/terminals watching the repo. Add Defender/AV exclusions for the project and npm cache. Retry from a fresh shell.
On WSL, clone to ~/projects (ext4) instead of /mnt/c. Shorten Windows paths to avoid MAX_PATH issues.
npm config set cache ~/.npm-cache
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
export PATH="$HOME/.npm-global/bin:$PATH"
rm -rf node_modules package-lock.json
npm cache clean --forcenpm ciRun containers with matching UID/GID or chown the workspace volume before npm install so the OS does not reject operations.
Advanced notes
EPERM on Windows often disappears when Developer Mode is enabled (symlink/rename policies are relaxed) and Defender exclusions are set. In CI, artifacts copied from root-owned build steps can cause EPERM in later non-root steps—clean and chown the workspace between steps. If a corporate policy forces read-only attributes, install dependencies in a per-user cache/prefix outside the locked directory.
Frequently asked questions
- What does "npm ERR! Error: EPERM: operation not permitted, <syscall> '<path>'" mean?
- EPERM indicates the OS blocked the requested filesystem operation even before checking permissions. In npm this happens when Windows/WSL or security tools deny rename/unlink/mkdir on node_modules, or when the path lives on a restricted mount or long path. It is common on Windows with Defender/AV, long paths, or VS Code holding handles; on WSL2 working on /mnt/c (NTFS); and in Docker/CI when the workspace is owned by a different user.
- How do I fix "npm ERR! Error: EPERM: operation not permitted, <syscall> '<path>'"?
- Windows/WSL often throws EPERM when npm touches files locked by AV/IDEs or on restricted mounts. Release locks, fix ownership, shorten paths, and re-run npm with user-owned locations.
- What causes "npm ERR! Error: EPERM: operation not permitted, <syscall> '<path>'"?
- Antivirus/Defender/EDR locking files under node_modules or cache Editors (VS Code) or watcher processes holding file handles NTFS/SMB mounts (WSL2/network) denying operations
- Is the "npm ERR! Error: EPERM: operation not permitted, <syscall> '<path>'" 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
- 📖Microsoft Docs: WSL file permission considerations(Official Docs)
- 📖npm Docs: Resolving permissions issues(Official Docs)
- 💬Stack Overflow: EPERM during npm install(Stack Overflow)
- 🐙