How to fix npm ERR! Error: EPERM: operation not permitted, <syscall> '<path>' in npm

npmBEGINNERMEDIUMUpdated Dec 2, 2025· 161 views

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
  1. Identify the blocked path and process
  2. Release locks and AV interference
  3. Move to a user-owned, POSIX-friendly path
  4. Use user-owned cache/prefix and clean temp files
npm — error
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
npm 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

  1. Antivirus/Defender/EDR locking files under node_modules or cache
  2. Editors (VS Code) or watcher processes holding file handles
  3. NTFS/SMB mounts (WSL2/network) denying operations
  4. Long path or read-only attribute on Windows directories
  5. Docker/CI running npm as a different user than the workspace owner
  6. Leftover root-owned artifacts from previous sudo installs

How to fix "npm ERR! Error: EPERM: operation not permitted, <syscall> '<path>'"

1Identify the blocked path and process

Copy the path from the error. On Windows, use Resource Monitor or handle.exe <path> to see which process holds it.

2Release locks and AV interference

Close VS Code/terminals watching the repo. Add Defender/AV exclusions for the project and npm cache. Retry from a fresh shell.

3Move to a user-owned, POSIX-friendly path

On WSL, clone to ~/projects (ext4) instead of /mnt/c. Shorten Windows paths to avoid MAX_PATH issues.

4Use user-owned cache/prefix and clean temp files
bash
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
5Retry with a clean install
bash
npm ci
6Align permissions in Docker/CI

Run 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