The E401 error occurs when npm cannot authenticate with a private registry, typically due to expired tokens, misconfigured .npmrc files, or protocol mismatches. This happens when credentials are missing, invalid, or the authentication token has expired.
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.
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.
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.
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