How to fix npm ERR! code ENOENT npm ERR! Error reading global configuration file in npm
This error occurs when npm cannot access or read the global configuration file, typically due to missing files, permission issues, or corrupted cache. It prevents npm commands from running and is usually fixable within minutes.
Quick fix
Fixes ENOENT
npm config get globalconfig
npm config get prefix- Check if npm global directories exist
- Clear the npm cache completely
- Delete the .npmrc file and let npm recreate it
- Fix npm directory ownership
npm config get globalconfignpm config get prefixnpm ERR! code ENOENTnpm ERR! Error reading global configuration file
What this error means
npm ERR! code ENOENT with 'Error reading global configuration file' means npm is looking for its global configuration file but cannot find it or doesn't have permission to read it. This can happen when the .npmrc file is deleted, corrupted, has wrong permissions, or when npm's global directories are misconfigured or missing.
Typical symptoms
- npm commands fail immediately with ENOENT error before any operation starts
- Error appears even on simple commands like 'npm --version' or 'npm install'
- Cannot install packages globally or locally
- Problem persists across different projects
- npm config commands fail to read or write settings
Common causes
- Global npm configuration file (~/.npmrc) is missing or deleted
- Corrupted npm cache containing invalid configuration data
- Permission denied on ~/.npmrc or npm's global directories
- Incorrect npm prefix configuration pointing to non-existent directory
- npm global directories were not created during Node.js installation
- Mixed ownership of npm directories from previous sudo usage
How to fix "npm ERR! code ENOENT npm ERR! Error reading global configuration file"
Verify that npm can locate its configuration:
npm config get globalconfig
npm config get prefixIf either path doesn't exist or shows an error, this is your problem.
Corrupted cache is a common cause. Clear it with:
npm cache clean --forceTry running an npm command again.
The global .npmrc file may be corrupted. Safely remove it:
# On macOS/Linux
rm ~/.npmrc
# On Windows
del %APPDATA%\\.npmrcThen run any npm command to trigger recreation.
If you previously ran npm with sudo, file ownership may be mixed:
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
sudo chown -R $(whoami) ~/.npm ~/.npmrcInstead of fixing permissions, configure npm to use a safe directory:
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'Add to your PATH in ~/.bashrc or ~/.zshrc:
export PATH=~/.npm-global/bin:$PATHFor the most reliable setup, use NVM or Volta:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install node
nvm use nodeVersion managers avoid system-wide permission problems entirely.
Advanced notes
The npm configuration hierarchy loads multiple files in order: npm's built-in config → global config → user config → project config → command-line flags. ENOENT specifically means npm can't find the global config file it expects. Running npm config ls shows all active configuration from all sources. The root cause is often previous use of sudo npm install -g, which creates root-owned files.
Frequently asked questions
- What does "ENOENT" mean?
- npm ERR! code ENOENT with 'Error reading global configuration file' means npm is looking for its global configuration file but cannot find it or doesn't have permission to read it. npmrc file is deleted, corrupted, has wrong permissions, or when npm's global directories are misconfigured or missing.
- How do I fix "ENOENT"?
- This error occurs when npm cannot access or read the global configuration file, typically due to missing files, permission issues, or corrupted cache. It prevents npm commands from running and is usually fixable within minutes.
- What causes "ENOENT"?
- Global npm configuration file (~/.npmrc) is missing or deleted Corrupted npm cache containing invalid configuration data Permission denied on ~/.npmrc or npm's global directories
- Is the "ENOENT" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚npm Official Documentation
- 📖npm Docs: npm config(Official Docs)
- 📖npm Docs: .npmrc Configuration(Official Docs)
- 🐙npm GitHub Issues(GitHub)