How to fix npm ERR! code E401 npm ERR! Incorrect or missing password in npm
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- Check if you're authenticated
- Log out and log back in
- Delete lock files and node_modules
- Verify your .npmrc file configuration
npm whoaminpm ERR! code E401npm 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
- 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
- Your Personal Access Token (PAT) in Azure DevOps has expired
- Mismatch between registry URL protocol (http vs https)
- Base64-encoded credentials in .npmrc are malformed
How to fix "npm ERR! code E401 npm ERR! Incorrect or missing password"
First, verify your current npm login status:
npm whoamiIf this returns 'unauthenticated' or an error, you need to log in.
Clear your current npm session and re-authenticate:
npm logout
npm loginWhen prompted, enter your npm username, password, and email address.
Remove cached dependencies:
rm -rf node_modules package-lock.json
npm cache clean --force
npm installCheck if your .npmrc file contains valid configuration:
cat ~/.npmrcFor public npm packages, your .npmrc should only contain:
registry=https://registry.npmjs.org/If using public npm packages only, reset your registry:
npm config set registry https://registry.npmjs.org/Then retry npm install.
If nothing else works, completely remove your .npmrc:
rm ~/.npmrc
npm login
npm installAdvanced 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
- 📚npm Official Documentation
- 📖npm Docs: npm login(Official Docs)
- 💬Stack Overflow: npm Authentication Errors(Stack Overflow)
- 📖npm Docs: Two-Factor Authentication(Official Docs)