How to fix npm ERR! Error: EPERM: operation not permitted, mkdir '<path>' in npm
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>- Check path ownership and free space
- Release AV/IDE locks
- Use user-owned cache/prefix and clean temp dirs
- Work on writable filesystems
ls -ld <path> || truestat $(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
- 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
- Docker/CI UID mismatch with mounted workspace
- Read-only or quota-limited filesystem
How to fix "npm ERR! Error: EPERM: operation not permitted, mkdir '<path>'"
ls -ld <path> || true
stat $(dirname <path>)
df -h <path>Close VS Code/terminals, add Defender/AV exclusions for the project and npm cache, then retry.
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 || trueOn WSL, move the repo to ext4 (~/projects). In Docker, run with matching UID/GID or chown the bind mount.
rm -rf node_modules package-lock.json
npm cache clean --force
npm ciAdvanced 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
- 📚npm Official Documentation
- 📖Microsoft Docs: WSL file permission considerations(Official Docs)
- 📖npm Docs: Permissions guidance(Official Docs)
- 💬Stack Overflow: Permission denied mkdir in npm install(Stack Overflow)
- 🐙