How to fix npm ERR! code E401 npm ERR! Incorrect or missing password in npm

npmINTERMEDIATEHIGHUpdated Dec 3, 2025· 214 views

The npm E401 error occurs when npm cannot authenticate your credentials or access token for the npm registry. This typically happens due to expired tokens, incorrect passwords, stale credentials in .npmrc files, or authentication configuration issues.

Quick fix

Fixes E401

npm whoami
  1. Check if you're authenticated
  2. Log out and log back in
  3. Delete lock files and node_modules
  4. Verify your .npmrc file configuration
npm — error
npm whoami
npm ERR! code E401
npm ERR! Incorrect or missing password

What this error means

The E401 Unauthorized error means npm failed to authenticate your request to the registry when installing packages. This commonly occurs when your stored access token has expired, you've recently changed your npm password, your .npmrc file contains malformed credentials, or you're trying to access a private package without valid authentication.

Typical symptoms

  • npm install fails immediately with E401 error
  • npm publish is rejected with authentication failure
  • Only certain private packages fail to install while public packages work
  • npm whoami returns 'unauthenticated'
  • Error persists even after successful npm login

Common causes

  1. Your npm authentication token or password has expired
  2. You changed your npm password but npm is using cached old credentials
  3. The .npmrc file contains an expired access token from a private registry
  4. Your Personal Access Token (PAT) in Azure DevOps has expired
  5. Mismatch between registry URL protocol (http vs https)
  6. Base64-encoded credentials in .npmrc are malformed

How to fix "npm ERR! code E401 npm ERR! Incorrect or missing password"

1Check if you're authenticated

First, verify your current npm login status:

bash
npm whoami

If this returns 'unauthenticated' or an error, you need to log in.

2Log out and log back in

Clear your current npm session and re-authenticate:

bash
npm logout
npm login

When prompted, enter your npm username, password, and email address.

3Delete lock files and node_modules

Remove cached dependencies:

bash
rm -rf node_modules package-lock.json
npm cache clean --force
npm install
4Verify your .npmrc file configuration

Check if your .npmrc file contains valid configuration:

bash
cat ~/.npmrc

For public npm packages, your .npmrc should only contain:

bash
registry=https://registry.npmjs.org/
5Reset to default npm registry

If using public npm packages only, reset your registry:

bash
npm config set registry https://registry.npmjs.org/

Then retry npm install.

6Nuclear option: Remove and regenerate .npmrc

If nothing else works, completely remove your .npmrc:

bash
rm ~/.npmrc
npm login
npm install

Advanced notes

The E401 error is intentionally generic for security—npm doesn't reveal whether authentication failed due to wrong password, expired token, or missing credentials. For CI/CD pipelines, use CI-specific token management: GitHub Actions use secrets, GitLab CI uses masked variables. Never commit .npmrc files with credentials to version control.

Frequently asked questions

What does "E401" mean?
The E401 Unauthorized error means npm failed to authenticate your request to the registry when installing packages. npmrc file contains malformed credentials, or you're trying to access a private package without valid authentication.
How do I fix "E401"?
The npm E401 error occurs when npm cannot authenticate your credentials or access token for the npm registry. This typically happens due to expired tokens, incorrect passwords, stale credentials in .npmrc files, or authentication configuration issues.
What causes "E401"?
Your npm authentication token or password has expired You changed your npm password but npm is using cached old credentials The .npmrc file contains an expired access token from a private registry
Is the "E401" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading