The E401 error occurs when npm cannot authenticate with your registry due to an expired, invalid, or misconfigured authentication token in your .npmrc file. This typically happens after password resets, token expiration, or when credentials are stored incorrectly.
npm E401 is an HTTP 401 Unauthorized error that indicates the authentication token npm is trying to use has been rejected by the registry. This can happen because the token has expired, the .npmrc file contains stale or incorrect credentials, the registry URL doesn't match your configuration, or your personal access token has been revoked.
First, check if npm recognizes any active login:
npm whoamiIf this returns 'unauthenticated', your credentials are not configured.
Log in again to refresh your credentials:
npm loginWhen prompted, enter your username, password or PAT, and confirm your email address.
Locate your .npmrc file at ~/.npmrc (macOS/Linux) or C:\Users\{username}\.npmrc (Windows).
Verify the registry URL matches your intended source and the _authToken line contains a valid token:
registry=https://registry.npmjs.org/
//registry.npmjs.org/:_authToken=npm_xxx...If the token looks invalid, delete it and re-run npm login.
Clear the cache and force reinstall:
rm -rf node_modules package-lock.json
npm cache clean --force
npm installIf using Azure DevOps or Azure Artifacts:
1. Go to Azure DevOps → User Settings → Personal Access Tokens
2. Generate a new PAT with Packaging (read) scope
3. Run:
npm install -g vsts-npm-auth
vsts-npm-auth -config .npmrcAs of November 2025, npm only supports Granular access tokens; legacy tokens are deprecated. Tokens have expiration dates you can configure. Unlike passwords, tokens cannot be recovered—you must regenerate them. The registry URL in .npmrc must use the exact same protocol as in package-lock.json or authentication headers may be stripped.
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