Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm install or publish stops with E401 and a password message

Errornpm ERR! code E401

Short answer

E401 means the registry did not accept the login npm sent. Usually the token in .npmrc is expired or removed, the credentials are written for another registry host, or the line has no registry prefix at all. Log in again for the exact registry, then check how the token line is written.

  • Applies to npm 10, npm 11, Node.js 22, Node.js 24
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the npm config lines that carry credentials, with the values hidden, and see which registry each one belongs to.

    npm config get registry
    grep -n "registry\|_authToken" .npmrc ~/.npmrc | sed 's/\(_authToken=\).*/\1<hidden>/'
  2. 2Match what you see, then jump to its fix

    1. 1E401 on a project that worked before, with no change to .npmrcThe access token has expired or was removedFix
    2. 2E401 only for scoped packages or only on a company registry, while public packages install fineThe credentials are for a different registry than the one npm callsFix
    3. 3A line that reads _authToken=... on its own, or a prefix that does not match the registry URLThe token line in .npmrc has no registry prefixFix

What does the error look like?

  • npm ERR! code E401
  • npm ERR! Incorrect or missing password.
  • npm error code E401

Cause 1 of 3

The access token has expired or was removed

1Check

Tokens on npmjs.com get an expiry date when they are created, and legacy access tokens were removed in November 2025. A token from before that date, or one past its expiry, is no longer accepted.

grep -n "_authToken" ~/.npmrc | sed 's/\(_authToken=\).*/\1<hidden>/'

2Fix

Log in again, or create a new granular access token on npmjs.com and put it in the place that reads it (a CI secret or ~/.npmrc). Prefer a read-only token for installs.

npm login

3Verify

Repeat the install or publish that failed.

npm install

Confirmed by docs.npmjs.com

Did this fix it?

Cause 2 of 3

The credentials are for a different registry than the one npm calls

1Check

Credentials in .npmrc are tied to one registry host and path. A token written for registry.npmjs.org is not sent to another host, and a scope may point at a registry that has no token.

npm config get registry
npm config get @myorg:registry

2Fix

Log in against the registry that owns the scope, and link the scope to it so npm sends the right login.

npm login --scope=@myorg --registry=https://registry.example.com/

3Verify

Install a package from that scope.

npm install @myorg/some-package

Confirmed by docs.npmjs.com

Did this fix it?

Cause 3 of 3

The token line in .npmrc has no registry prefix

1Check

npm only reads credentials that are scoped to a registry with a //host/path/: prefix. A bare _authToken line is shown as bad configuration in the docs.

grep -n "_authToken" .npmrc ~/.npmrc | sed 's/\(_authToken=\).*/\1<hidden>/'

2Fix

Write the line with the registry host in front, matching the registry setting.

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

3Verify

Run the install again with the variable set in the shell.

export NPM_TOKEN=your-token-here
npm install

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Give every token an expiry you can see, and put the renewal date in your calendar.
  • Keep tokens in CI secrets, never in a committed .npmrc.
  • Use a read-only token for installs and a separate publishing token.
  • Write every credential line with its registry prefix.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.