npm / npm

npm ERR! code E401

Fix npm ERR! code E401 authentication failures when installing or publishing packages.

Category
npm
Error signature
npm ERR! code E401
Quick fix
Run npm login for the correct registry, then retry the install or publish command.
Updated

What this error means

npm ERR! code E401 means npm reached a registry that requires authentication, but the current credentials were missing, expired, or rejected.

Common causes

Quick fixes

  1. Check which registry npm is using:

    npm config get registry
  2. Log in again:

    npm login
  3. If the package uses a scope, verify the scoped registry:

    npm config get @your-scope:registry
  4. Retry the original command.

Step-by-step troubleshooting

  1. Run npm whoami to confirm whether npm sees a valid logged-in user.
  2. Inspect project and user .npmrc files for stale registry or token entries.
  3. Confirm that private package scopes point to the correct registry host.
  4. For publishing, add the OTP when your npm account requires two-factor authentication.
  5. If CI fails, rotate the npm token and update the CI secret value.

FAQ

Does E401 always mean my password is wrong?

No. It usually means npm did not send an accepted token for the registry it contacted.

Should I commit my npm token?

No. Keep tokens in your user .npmrc or CI secrets, never in source control.

Can this happen for public packages?

Yes, if your npm config points public installs at a private registry that requires authentication.