npm cannot remove its temp .DELETE/.staging folders because they are root-owned or locked. Clean them, move to a user-writable prefix, and prevent AV or other processes from holding the files.
npm stages global installs in temporary .staging folders and cleans them with unlink/rename. If those folders are owned by root (from earlier sudo installs) or locked by AV/EDR, npm's unlink fails and the install aborts, leaving partially staged content. The problem is common on Windows/WSL when Defender scans node_modules, and on macOS/Linux when mixing sudo and non-sudo installs leaves root-owned temp artifacts under the global prefix.
sudo rm -rf $(npm config get prefix)/lib/node_modules/.staging \
$(npm config get prefix)/lib/node_modules/.*.DELETE 2>/dev/null || truemkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
export PATH="$HOME/.npm-global/bin:$PATH"
# or install Node with nvm to keep globals in $HOMEsudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}Add your global prefix to AV exclusions so unlink/rename is not blocked. Close VS Code or terminals that keep handles open.
npm cache clean --force
npm install -g <package>In Docker/CI, ensure npm runs as the filesystem owner or set prefix to a workspace path owned by the job user; root-owned layers will block unlink. Windows/WSL users often hit EPERM/EACCES from Defender scans—Developer Mode plus AV exclusions reduce locks on temp files. Avoid mixing sudo and user installs; it consistently leaves root-owned staging folders that require manual cleanup.
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