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

npmBEGINNERMEDIUMUpdated Dec 2, 2025· 292 views

npm cannot create a directory because the filesystem or policy blocks it (Windows/WSL AV locks, root-owned prefixes, read-only mounts). Use user-owned paths, release locks, and retry.

Quick fix

Fixes npm ERR! Error: EPERM: operation not permitted, mkdir '<path>'

ls -ld <path> || true
stat $(dirname <path>)
df -h <path>
  1. Check path ownership and free space
  2. Release AV/IDE locks
  3. Use user-owned cache/prefix and clean temp dirs
  4. Work on writable filesystems
npm — error
ls -ld <path> || true
stat $(dirname <path>)
df -h <path>
npm ERR! Error: EPERM: operation not permitted, mkdir '<path>'

What this error means

mkdir failed before permission checks completed, usually because Windows/WSL policy or locks blocked directory creation. npm hits this when writing to node_modules, cache, or global prefixes that are locked by AV, owned by another user, or on restricted mounts. It is frequent on Windows with Defender/EDR, WSL2 on /mnt/c, and Docker/CI when running as a different user than the volume owner. Root-owned remnants from earlier sudo installs can also cause mkdir to be rejected.

Typical symptoms

  • npm install/ci fails with EPERM: mkdir '<path>'
  • Works with sudo/Admin but fails otherwise
  • node_modules/.staging or cache dirs persist across failures
  • Defender/AV alerts when npm runs
  • Happens more on Windows/WSL/network paths than local ext4

Common causes

  1. AV/EDR or file watchers locking directories during creation
  2. Root-owned global prefix or node_modules from prior sudo installs
  3. NTFS/SMB mounts (WSL2, network shares) denying mkdir
  4. Docker/CI UID mismatch with mounted workspace
  5. Read-only or quota-limited filesystem

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

1Check path ownership and free space
bash
ls -ld <path> || true
stat $(dirname <path>)
df -h <path>
2Release AV/IDE locks

Close VS Code/terminals, add Defender/AV exclusions for the project and npm cache, then retry.

3Use user-owned cache/prefix and clean temp dirs
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/.staging 2>/dev/null || true
4Work on writable filesystems

On WSL, move the repo to ext4 (~/projects). In Docker, run with matching UID/GID or chown the bind mount.

5Retry install cleanly
bash
rm -rf node_modules package-lock.json
npm cache clean --force
npm ci

Advanced notes

Corporate laptops sometimes apply AppLocker/Controlled Folder Access, blocking mkdir in developer directories; adding approved exclusions or using user-owned prefixes in $HOME avoids the policy. In CI, make sure the workspace isn’t mounted read-only and that earlier root steps didn’t leave .staging directories. For Windows long-path scenarios, enabling longPaths in git and npm can help but the primary fix is using a shorter, user-writable path.

Frequently asked questions

What does "npm ERR! Error: EPERM: operation not permitted, mkdir '<path>'" mean?
mkdir failed before permission checks completed, usually because Windows/WSL policy or locks blocked directory creation. npm hits this when writing to node_modules, cache, or global prefixes that are locked by AV, owned by another user, or on restricted mounts. It is frequent on Windows with Defender/EDR, WSL2 on /mnt/c, and Docker/CI when running as a different user than the volume owner.
How do I fix "npm ERR! Error: EPERM: operation not permitted, mkdir '<path>'"?
npm cannot create a directory because the filesystem or policy blocks it (Windows/WSL AV locks, root-owned prefixes, read-only mounts). Use user-owned paths, release locks, and retry.
What causes "npm ERR! Error: EPERM: operation not permitted, mkdir '<path>'"?
AV/EDR or file watchers locking directories during creation Root-owned global prefix or node_modules from prior sudo installs NTFS/SMB mounts (WSL2, network shares) denying mkdir
Is the "npm ERR! Error: EPERM: operation not permitted, mkdir '<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