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.
Fixes npm ERR! Error: EPERM: operation not permitted, mkdir '<path>'
ls -ld <path> || true
stat $(dirname <path>)
df -h <path>ls -ld <path> || truestat $(dirname <path>)df -h <path>npm ERR! Error: EPERM: operation not permitted, mkdir '<path>'
On this page
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.
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 ciCorporate 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.