The ENEEDAUTH error occurs when npm cannot find valid authentication credentials for the registry you're trying to access. This typically happens after logging out, using an expired token, or misconfiguring your .npmrc file.
Fixes ENEEDAUTH
npm whoaminpm whoaminpm ERR! code ENEEDAUTHnpm ERR! Not logged in
On this page
The ENEEDAUTH error means npm could not find valid authentication credentials when attempting to access a registry. This happens when you have logged out or your session has expired, your authentication token has been revoked or expired, your .npmrc file is misconfigured or missing credentials, or you're trying to access a private registry without proper authentication setup.
Run npm whoami to see if you're authenticated:
npm whoamiIf it returns 'unauthenticated', you need to log in.
Run the npm login command and enter your credentials:
npm loginVerify with: npm whoami
Ensure your .npmrc file has the correct format:
registry=https://registry.npmjs.org/
@my-scope:registry=https://my.private.registry/
//my.private.registry/:_authToken=YOUR_TOKEN_HEREIn GitHub Actions:
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}Clear cache in case cached credentials are stale:
npm cache clean --force
npm installIf the above steps don't work, create a new token at npmjs.com/settings/tokens and update .npmrc:
npm logout
npm loginThe ENEEDAUTH error is intentionally generic because npm's authentication logic doesn't distinguish between 'logged out', 'token expired', 'wrong registry', and 'missing credentials'. For npm 9.3.1+, authentication tokens must be scoped (prefixed with //domain/:_authToken=) rather than global.