The ENOENT error occurs when npm cannot find the global packages directory (typically /usr/local/lib/node_modules), usually because the directory doesn't exist or has permission issues. This prevents global package installations and updates from working correctly.
ENOENT stands for 'Error: NO ENTry'. When npm tries to access the global packages directory to install or manage global packages, the system cannot find the specified path. This typically happens when the directory structure is missing, deleted, or inaccessible due to permission restrictions.
Verify where npm thinks the global directory should be:
npm config get prefix
npm config list | grep prefixNote the path returned. If this path doesn't exist, it's the root cause.
Check if the directory actually exists:
ls -la /usr/local/lib/node_modules
# or:
ls -la $(npm config get prefix)/lib/node_modulesIf you get a "No such file or directory" error, the directory needs to be created.
If the directory doesn't exist, create it with proper permissions:
mkdir -p /usr/local/lib/node_modules
mkdir -p /usr/local/binThen ensure you own these directories:
sudo chown -R $(whoami) /usr/local/lib/node_modules
sudo chown -R $(whoami) /usr/local/binInstead of fixing system directories, configure npm to use a directory in your home folder:
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'Then add to your PATH in ~/.bashrc or ~/.zshrc:
export PATH=~/.npm-global/bin:$PATHApply changes: source ~/.bashrc
Test that global installations work:
npm install -g npm
npm list -g --depth=0On systems using nvm (Node Version Manager), ensure npm's prefix is not explicitly set in ~/.npmrc. If you see 'nvm is not compatible with the npm config "prefix" option', run npm config delete prefix to remove itβnvm manages node/npm paths automatically. For Docker containers, consider using a custom prefix during installation.
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