The ENEEDAUTH error occurs when npm cannot authenticate with the registry. Run npm login to authenticate, or check your .npmrc for missing or expired tokens.
The ENEEDAUTH error indicates npm cannot find valid authentication credentials for the registry you're trying to access. This commonly occurs when publishing packages, installing from private registries, or accessing scoped packages. Even if you've logged in before, tokens can expire, .npmrc configuration can be incorrect, or you might be logged into the wrong registry.
Authenticate with the registry:
# Log in to npm public registry
npm login
# Log in to specific registry
npm login --registry=https://your-registry.com
# For npm 9+ with private registries
npm login --auth-type=legacy --registry=https://your-registry.comCheck if you're authenticated:
# Check who you're logged in as
npm whoami
# Check for specific registry
npm whoami --registry=https://your-registry.comIf this fails, you're not logged in.
Verify your .npmrc has correct tokens:
# View .npmrc contents
cat ~/.npmrc
# Should contain something like:
# //registry.npmjs.org/:_authToken=npm_xxxxxFor scoped packages:
@myorg:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NPM_TOKEN}Configure tokens for automated environments:
# Create .npmrc with token from environment variable
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrcGitHub Actions:
- name: Setup npm auth
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrcSome private registries require always-auth:
# Add to .npmrc
echo "always-auth=true" >> .npmrc
# Or set via npm config
npm config set always-auth trueIf tokens are stale, start fresh:
# Remove old config
rm ~/.npmrc
# Log in again
npm login
# Verify
npm whoaminpm 9+ changed authentication behavior:
- Defaults to web-based login
- Some private registries need --auth-type=legacy
- npm config set may not work for auth in npm 10+
For private registries like Artifactory or Nexus:
- Enable "npm Bearer Token Realm" in the server config
- Use legacy auth type if web login fails
.npmrc token formats:
# Bearer token (modern)
//registry.url/:_authToken=TOKEN
# Base64 auth (legacy)
//registry.url/:username=USER
//registry.url/:_password=BASE64_PASSnpm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm