The npm E401 error occurs when your authentication token or credentials for a private npm registry have expired, been invalidated, or are misconfigured in your .npmrc file. This prevents npm install from accessing private packages you have permission to use.
npm returns a 401 Unauthorized error when it tries to authenticate with a registry and the credentials fail validation. This usually means your authentication token has expired, your password was reset, your .npmrc contains stale credentials, or the token was revoked.
Check whether npm recognizes you as logged in:
npm whoamiIf this returns 'unauthenticated', you need to log in.
Locate your .npmrc file:
cat ~/.npmrcIf you see an old authToken, it may be expired.
Log in again to refresh your credentials:
npm loginThis will overwrite the old token in your .npmrc with a fresh one.
If using Azure DevOps Artifacts:
1. Go to Azure DevOps → Personal Access Tokens
2. Regenerate expired tokens
3. Run:
vsts-npm-auth -config .npmrcIf npm v7+ is in use, package-lock.json may contain cached registry credentials:
rm package-lock.json
npm installAs a last resort, delete and recreate your .npmrc:
rm ~/.npmrc
npm loginThe npm E401 error has several nuances: Package-lock.json can cache resolved URLs with embedded credentials; upgrading npm v6→v7 sometimes breaks private registry compatibility if the protocol doesn't match exactly. Azure DevOps uses personal access tokens with expiration dates—these must be renewed separately using vsts-npm-auth.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error