npm install or publish stops with E401 and a password message
npm ERR! code E401Short 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.
Fix it fast
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>/'2Match what you see, then jump to its fix
- 1
E401 on a project that worked before, with no change to .npmrcThe access token has expired or was removedFix - 2
E401 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
A 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
- 1
What does the error look like?
npm ERR! code E401npm 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 login3Verify
Repeat the install or publish that failed.
npm installConfirmed by docs.npmjs.com
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:registry2Fix
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-packageConfirmed by docs.npmjs.com
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 installConfirmed by docs.npmjs.com
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
npm install fails with E401 against a private Nexus registry
npm error Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
E401 means the registry asked for credentials and npm sent none that it accepts.
4 causes, each with a fixBack 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 fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack 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 fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fix