How to fix npm error code E401 npm error Incorrect or missing password. in npm
npm E401 means your registry credentials are wrong or expired. Fix by re-running npm login or updating the auth token in .npmrc.
Quick fix
Fixes E401
find ~ -name '.npmrc' -type f
cat ~/.npmrc- Verify the correct registry URL and locate your .npmrc file
- Check and fix .npmrc configuration syntax
- Regenerate and update your authentication token
- Delete package-lock.json and clear npm cache
find ~ -name '.npmrc' -type fcat ~/.npmrcnpm error code E401 npm error Incorrect or missing password.
What this error means
The E401 error indicates an authentication failure when npm tries to access a private package registry. It occurs at the HTTP level when the registry server rejects your credentials, whether that's because your authentication token has expired, is malformed, is missing entirely, or the .npmrc configuration points to the wrong registry URL.
Typical symptoms
- npm install fails with E401 error and halts dependency installation
- Package manager can access public npm registry but fails on scoped private packages
- npm login command succeeds, but subsequent install commands still fail
- CI/CD pipelines fail during npm install even with authentication tokens configured
- Error message includes 'Incorrect or missing password' or 'Bearer authorization'
Common causes
- Authentication token in .npmrc has expired or been revoked
- Incorrect .npmrc syntax—missing colon, wrong registry URL format, or protocol mismatch
- Token not base64 encoded when required by the registry (especially Azure Artifacts)
- Missing :_authToken or :always-auth configuration in .npmrc
- Wrong registry URL in .npmrc—publishing/installing from public registry instead of private
- package-lock.json cached with incorrect protocol—npm v7+ requires exact protocol match
How to fix "npm error code E401 npm error Incorrect or missing password."
List all .npmrc files on your system:
find ~ -name '.npmrc' -type f
cat ~/.npmrcIf you have multiple .npmrc files, npm uses them in order: project-level → user-level → global.
Verify the syntax matches your registry type:
registry=https://your-registry-url.com/npm/
//your-registry-url.com/npm/:_authToken=your-token-here
//your-registry-url.com/npm/:always-auth=trueFor scoped packages:
@org:registry=https://your-registry-url.com/npm/
//your-registry-url.com/npm/:_authToken=your-token-hereYour token may have expired. For GitHub Packages:
npm login --scope=@owner --registry=https://npm.pkg.github.comFor Azure Artifacts:
npx vsts-npm-auth -config .npmrcIf the protocol doesn't match your package-lock.json:
rm package-lock.json
npm cache clean --force
npm installVerify your setup works:
npm whoami --registry=https://your-registry.comIf successful, you'll see your username.
Advanced notes
npm v9+ changed to web-based authentication by default. When you configure @scope:registry=..., npm only routes @scope/* packages to that registry. Unscoped packages still go to the default registry. Never commit plaintext tokens to version control—use environment variables in CI/CD.
Frequently asked questions
- What does "E401" mean?
- The E401 error indicates an authentication failure when npm tries to access a private package registry. npmrc configuration points to the wrong registry URL.
- How do I fix "E401"?
- npm E401 means your registry credentials are wrong or expired. Fix by re-running npm login or updating the auth token in .npmrc.
- What causes "E401"?
- Authentication token in .npmrc has expired or been revoked Incorrect .npmrc syntax—missing colon, wrong registry URL format, or protocol mismatch Token not base64 encoded when required by the registry (especially Azure Artifacts)
- 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
- 📚npm Official Documentation
- 📖npm .npmrc configuration documentation(Official Docs)
- 💬Stack Overflow: npm authentication(Stack Overflow)
- 🐙npm GitHub repository(GitHub)