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.
Fixes npm ERR! code ENEEDAUTH npm ERR! need auth This command requires you to be logged in
# 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.com# Log in to npm public registrynpm login# Log in to specific registrynpm login --registry=https://your-registry.com# For npm 9+ with private registriesnpm login --auth-type=legacy --registry=https://your-registry.comnpm ERR! code ENEEDAUTHnpm ERR! need auth This command requires you to be logged in
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_PASS