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.
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.
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.
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.
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm