npm cannot create the global package directory because the prefix is unwritable or owned by root. Use nvm/user prefixes or fix ownership, clear staging, then reinstall.
Global installs create a package directory under prefix/lib/node_modules before copying files. If that parent directory is owned by root or mounted read-only, npm's mkdir syscall fails with EACCES and the install stops. Temporary .staging directories from past sudo installs can also remain root-owned, preventing new directories from being created. This shows up on macOS Homebrew installs, Linux servers with hardened /usr/local permissions, Docker/CI jobs running as non-root, and Windows/WSL when corporate AV interferes with mkdir inside node_modules.
npm config get prefix
ls -ld $(npm config get prefix)/lib/node_modules
sudo ls -ld $(npm config get prefix)/lib/node_modules/.staging 2>/dev/null || trueexport NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \ . "$NVM_DIR/nvm.sh"
nvm install --lts
# or
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
export PATH="$HOME/.npm-global/bin:$PATH"sudo rm -rf $(npm config get prefix)/lib/node_modules/.staging 2>/dev/null || true
npm cache clean --forcesudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}npm install -g <package>Close editors holding node_modules, add Defender exclusions for your prefix, and retry from an elevated shell if required by policy.
On macOS with Homebrew, ensure /usr/local or /opt/homebrew remains owned by the brew user; reinstalling Node via nvm/fnm keeps globals under $HOME and avoids permission drift. In Docker/CI, set npm config prefix to a workspace-owned path or run as the image owner to avoid EACCES during mkdir. Corporate AV/EDR on Windows/WSL can lock mkdir/unlink; exclusions for node_modules and temp folders prevent recurring failures.
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error