How to fix npm ERR! Error: EACCES: permission denied, scandir '<path>' in npm

npmBEGINNERMEDIUMUpdated Dec 2, 2025· 229 views

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>
  1. Inspect the path from the error
  2. Fix permissions for the workspace
  3. Move npm cache/prefix to user-owned paths
  4. Release locks from AV/IDEs
npm — error
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

  1. Root-owned node_modules or cache directories from earlier sudo installs
  2. Read-only or ACL-restricted mounts (NTFS/SMB/AFS, corporate lockdown)
  3. Antivirus/Defender/EDR blocking directory access
  4. IDE/editor watchers holding handles inside node_modules
  5. Docker/CI running as non-owner of the workspace volume
  6. WSL2 working on /mnt/c instead of the Linux filesystem

How to fix "npm ERR! Error: EACCES: permission denied, scandir '<path>'"

1Inspect the path from the error
bash
ls -ld <path>
stat <path>
2Fix permissions for the workspace
bash
sudo chown -R $(whoami) .
chmod -R u+rw node_modules
3Move npm cache/prefix to user-owned paths
bash
npm config set cache ~/.npm-cache
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
export PATH="$HOME/.npm-global/bin:$PATH"
4Release locks from AV/IDEs

Add Defender/AV exclusions for the project and npm cache; close VS Code/terminals holding node_modules so scandir can read the directory.

5Use a writable filesystem

On WSL, clone to ~/projects (ext4) instead of /mnt/c. In Docker, run with matching UID/GID or chown the bind-mounted workspace.

6Retry with a clean install
bash
npm cache clean --force
npm ci

ci 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