How to fix npm ERR! code ENOENT npm ERR! Error reading global configuration file in npm

npmBEGINNERMEDIUMUpdated Dec 3, 2025· 140 views

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
  1. Check if npm global directories exist
  2. Clear the npm cache completely
  3. Delete the .npmrc file and let npm recreate it
  4. Fix npm directory ownership
npm — error
npm config get globalconfig
npm config get prefix
npm ERR! code ENOENT
npm 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

  1. Global npm configuration file (~/.npmrc) is missing or deleted
  2. Corrupted npm cache containing invalid configuration data
  3. Permission denied on ~/.npmrc or npm's global directories
  4. Incorrect npm prefix configuration pointing to non-existent directory
  5. npm global directories were not created during Node.js installation
  6. Mixed ownership of npm directories from previous sudo usage

How to fix "npm ERR! code ENOENT npm ERR! Error reading global configuration file"

1Check if npm global directories exist

Verify that npm can locate its configuration:

bash
npm config get globalconfig
npm config get prefix

If either path doesn't exist or shows an error, this is your problem.

2Clear the npm cache completely

Corrupted cache is a common cause. Clear it with:

bash
npm cache clean --force

Try running an npm command again.

3Delete the .npmrc file and let npm recreate it

The global .npmrc file may be corrupted. Safely remove it:

bash
# On macOS/Linux
rm ~/.npmrc

# On Windows
del %APPDATA%\\.npmrc

Then run any npm command to trigger recreation.

4Fix npm directory ownership

If you previously ran npm with sudo, file ownership may be mixed:

bash
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
sudo chown -R $(whoami) ~/.npm ~/.npmrc
5Configure npm to use a custom global directory

Instead of fixing permissions, configure npm to use a safe directory:

bash
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'

Add to your PATH in ~/.bashrc or ~/.zshrc:

bash
export PATH=~/.npm-global/bin:$PATH
6Use a Node version manager

For the most reliable setup, use NVM or Volta:

bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install node
nvm use node

Version 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