How to fix npm ERR! Error: EACCES: permission denied, scandir '<path>' in npm
npm cannot list a directory (node_modules/cache/global path) because it is unreadable or locked. Fix ownership/ACLs, move npm to user-owned dirs, and release AV/IDE locks.
Quick fix
Fixes npm ERR! Error: EACCES: permission denied, scandir '<path>'
ls -ld <path>
stat <path>- Inspect the path from the error
- Fix permissions for the workspace
- Move npm cache/prefix to user-owned paths
- Release locks from AV/IDEs
ls -ld <path>stat <path>npm ERR! Error: EACCES: permission denied, scandir '<path>'
What this error means
npm calls scandir to enumerate directories while resolving dependencies, reading cache entries, and linking global binaries. If the target directory is unreadable, root-owned, on a read-only mount, or held by another process, scandir throws EACCES and npm aborts. This occurs after sudo installs leave root-owned folders, when node_modules lives on NTFS/SMB with restrictive ACLs (WSL2, network shares), or when antivirus/EDR/IDEs block directory reads. CI/Docker runs as non-root against root-owned workspaces show the same failure.
Typical symptoms
- npm install/ci fails with EACCES: scandir '<path>'
- Works with sudo/Admin but not as a regular user
- node_modules or cache subdirs show root-owned permissions
- npm cache verify reports unreadable cache directories
- On Windows/WSL, scandir errors reference Windows or network paths
- In Docker/CI, scandir fails on a bind-mounted workspace
Common causes
- Root-owned node_modules or cache directories from earlier sudo installs
- Read-only or ACL-restricted mounts (NTFS/SMB/AFS, corporate lockdown)
- Antivirus/Defender/EDR blocking directory access
- IDE/editor watchers holding handles inside node_modules
- Docker/CI running as non-owner of the workspace volume
- WSL2 working on /mnt/c instead of the Linux filesystem
How to fix "npm ERR! Error: EACCES: permission denied, scandir '<path>'"
ls -ld <path>
stat <path>sudo chown -R $(whoami) .
chmod -R u+rw node_modulesnpm config set cache ~/.npm-cache
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
export PATH="$HOME/.npm-global/bin:$PATH"Add Defender/AV exclusions for the project and npm cache; close VS Code/terminals holding node_modules so scandir can read the directory.
On WSL, clone to ~/projects (ext4) instead of /mnt/c. In Docker, run with matching UID/GID or chown the bind-mounted workspace.
npm cache clean --force
npm cici recreates node_modules and ensures directory permissions are consistent.
Advanced notes
Network/SMB shares can deny Unix read bits even when Windows shows access; cloning locally avoids scandir EACCES. Corporate macOS images may require admin to read /usr/local/lib/node_modules—keep globals in $HOME via nvm/fnm. In CI, permissions may drift if earlier steps ran as root; chown the workspace before installing to avoid unreadable cache directories.
Frequently asked questions
- What does "npm ERR! Error: EACCES: permission denied, scandir '<path>'" mean?
- npm calls scandir to enumerate directories while resolving dependencies, reading cache entries, and linking global binaries. If the target directory is unreadable, root-owned, on a read-only mount, or held by another process, scandir throws EACCES and npm aborts. This occurs after sudo installs leave root-owned folders, when node_modules lives on NTFS/SMB with restrictive ACLs (WSL2, network shares), or when antivirus/EDR/IDEs block directory reads.
- How do I fix "npm ERR! Error: EACCES: permission denied, scandir '<path>'"?
- npm cannot list a directory (node_modules/cache/global path) because it is unreadable or locked. Fix ownership/ACLs, move npm to user-owned dirs, and release AV/IDE locks.
- What causes "npm ERR! Error: EACCES: permission denied, scandir '<path>'"?
- Root-owned node_modules or cache directories from earlier sudo installs Read-only or ACL-restricted mounts (NTFS/SMB/AFS, corporate lockdown) Antivirus/Defender/EDR blocking directory access
- Is the "npm ERR! Error: EACCES: permission denied, scandir '<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
- 📖npm Docs: Resolving EACCES for npm(Official Docs)
- 📖Microsoft Docs: WSL file permission considerations(Official Docs)
- 💬Stack Overflow: Permission denied errors in npm install(Stack Overflow)
- 🐙