How to fix npm ERR! ENOENT: no such file or directory, open '.npmrc' in npm

npmBEGINNERLOWUpdated Dec 6, 2025ยท 149 views

The ENOENT .npmrc error occurs when npm expects a configuration file that doesn't exist. This is usually not critical unless the file is referenced explicitly.

Quick fix

Fixes npm ERR! ENOENT: no such file or directory, open '.npmrc'

# Check if your project needs one
ls -la .npmrc

# Check npm config sources
npm config list --json | jq
  1. Check if .npmrc is needed
  2. Create basic .npmrc
  3. Check environment variables
  4. For private registry access
npm โ€” error
# Check if your project needs one
ls -la .npmrc
# Check npm config sources
npm config list --json | jq
npm ERR! ENOENT: no such file or directory, open '.npmrc'

What this error means

.npmrc files contain npm configuration. They can exist at multiple levels: project (./npmrc), user (~/.npmrc), and global. The ENOENT error for .npmrc usually means npm was told to look for one that doesn't exist. This often happens when environment variables or other configuration point to a non-existent .npmrc file, or when a project expects .npmrc but it wasn't committed or created.

Typical symptoms

  • npm commands fail looking for .npmrc
  • Error mentions specific .npmrc path
  • CI/CD environment missing config
  • Private registry access fails
  • Configuration expected but not present
  • npm config commands fail

Common causes

  1. Project expects .npmrc that doesn't exist
  2. NPM_CONFIG_USERCONFIG points to missing file
  3. CI/CD not configured with .npmrc
  4. .npmrc not committed to repo
  5. Environment mismatch between machines
  6. Referenced in other config but missing

How to fix "npm ERR! ENOENT: no such file or directory, open '.npmrc'"

1Check if .npmrc is needed

Determine if .npmrc is required:

bash
# Check if your project needs one
ls -la .npmrc

# Check npm config sources
npm config list --json | jq
2Create basic .npmrc

Create if needed:

bash
# Empty file is valid
touch .npmrc

# Or with content
echo "registry=https://registry.npmjs.org/" > .npmrc
3Check environment variables

Look for misconfigured paths:

bash
echo $NPM_CONFIG_USERCONFIG
echo $NPM_CONFIG_GLOBALCONFIG

# Unset if pointing to wrong place
unset NPM_CONFIG_USERCONFIG
4For private registry access

Set up authentication:

bash
# .npmrc for private registry
registry=https://npm.company.com/
//npm.company.com/:_authToken=${NPM_TOKEN}

# Keep out of git!
echo ".npmrc" >> .gitignore
5Use project .npmrc template

Document required config:

bash
# .npmrc.example (commit this)
registry=https://npm.company.com/

# README instructions
# Copy .npmrc.example to .npmrc and add token
6Fix CI/CD configuration

Set up config in CI:

yaml
# GitHub Actions
steps:
  - name: Create .npmrc
    run: |
      echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
    env:
      NPM_TOKEN: \${{ secrets.NPM_TOKEN }}

Advanced notes

Multiple .npmrc files are merged with project > user > global precedence. Never commit auth tokens to .npmrc - use environment variables. In monorepos, .npmrc at root applies to all workspaces. Some CI systems have built-in npm authentication that doesn't require .npmrc. Use npm config ls -l to see all config sources.

Frequently asked questions

What does "npm ERR! ENOENT: no such file or directory, open '.npmrc'" mean?
npmrc files contain npm configuration. npmrc), and global. npmrc usually means npm was told to look for one that doesn't exist.
How do I fix "npm ERR! ENOENT: no such file or directory, open '.npmrc'"?
The ENOENT .npmrc error occurs when npm expects a configuration file that doesn't exist. This is usually not critical unless the file is referenced explicitly.
What causes "npm ERR! ENOENT: no such file or directory, open '.npmrc'"?
Project expects .npmrc that doesn't exist NPM_CONFIG_USERCONFIG points to missing file CI/CD not configured with .npmrc
Is the "npm ERR! ENOENT: no such file or directory, open '.npmrc'" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading