Np: User authentication fails

Created on 27 Feb 2020  路  4Comments  路  Source: sindresorhus/np

Description

I ran "np" but it failed telling me "You must be logged in. Use npm login and try again.". I executed "npm whoami" and saw that I am already logged in. So there seems to be a bug.

Steps to reproduce

  1. Use a scoped package
  2. Add "release": "np" to your "scripts" section in "package.json"
  3. Run "yarn release"

.np-config.json

{
  "anyBranch": false,
  "cleanup": true,
  "contents": "proto",
  "preview": true,
  "tests": true,
  "yarn": true
}

Expected behavior

"Verify user is authenticated" to not fail.

Environment

np - 6.2.0
Node.js - 12.11.0
npm - 6.10.1
Git - 2.16.2.windows.1
OS - Windows 10

Most helpful comment

I added a script to my package that runs npm whoami. Running that via yarn fails as well; this does not appear to be specific to np.

package.json:

  ...
  "scripts": {
    "test-who": "npm whoami"
  }

running via npm

mlclay@gram:~/projects/sandbox$ npm whoami
mlclay

running via yarn

mlclay@gram:~/projects/sandbox$ yarn test-who
yarn run v1.17.3
$ npm whoami
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/lucas/.npm/_logs/2020-03-11T15_03_49_396Z-debug.log
error Command failed with exit code 1.

Update

While writing this, I came across the yarn login command. https://classic.yarnpkg.com/en/docs/cli/login/

After I ran yarn login and entered my username/email, then my subsequent yarn test-who and yarn np commands worked without the authentication issue we ran in to.

mlclay@gram:~/projects/sandbox$ yarn test-who
yarn run v1.17.3
$ npm whoami
mlclay

All 4 comments

I added a script to my package that runs npm whoami. Running that via yarn fails as well; this does not appear to be specific to np.

package.json:

  ...
  "scripts": {
    "test-who": "npm whoami"
  }

running via npm

mlclay@gram:~/projects/sandbox$ npm whoami
mlclay

running via yarn

mlclay@gram:~/projects/sandbox$ yarn test-who
yarn run v1.17.3
$ npm whoami
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/lucas/.npm/_logs/2020-03-11T15_03_49_396Z-debug.log
error Command failed with exit code 1.

Update

While writing this, I came across the yarn login command. https://classic.yarnpkg.com/en/docs/cli/login/

After I ran yarn login and entered my username/email, then my subsequent yarn test-who and yarn np commands worked without the authentication issue we ran in to.

mlclay@gram:~/projects/sandbox$ yarn test-who
yarn run v1.17.3
$ npm whoami
mlclay

The @mlclay's method also helped me

@mlclay method worked for me as well

@mlclay's workaround didn't worked for me :slightly_frowning_face:
But npx np did

Was this page helpful?
0 / 5 - 0 ratings

Related issues

papb picture papb  路  6Comments

xxczaki picture xxczaki  路  6Comments

jescalan picture jescalan  路  3Comments

dotconnor picture dotconnor  路  4Comments

sindresorhus picture sindresorhus  路  7Comments