cli: Error: Could not login to npm
I’ve seen this a few times now: I run the CLI, it fails. If I run npm whoami
then give npx semantic-release-cli setup
another time, it works! Not sure what the deal is, as I’m not changing my login status.
First attempt fails:
$ npx semantic-release-cli setup
? What is your npm registry? https://registry.npmjs.org/
? What is your npm username? zeke
ERR! semantic-release Error: Could not login to npm.
ERR! semantic-release at getNpmToken (/usr/local/lib/node_modules/semantic-release-cli/src/lib/npm.js:51:21)
ERR! semantic-release at <anonymous>
ERR! semantic-release at process._tickCallback (internal/process/next_tick.js:188:7)
ERR! semantic-release { Error: Could not login to npm.
ERR! semantic-release at getNpmToken (/usr/local/lib/node_modules/semantic-release-cli/src/lib/npm.js:51:21)
ERR! semantic-release at <anonymous>
ERR! semantic-release at process._tickCallback (internal/process/next_tick.js:188:7)
ERR! semantic-release stack: 'Error: Could not login to npm.\n at getNpmToken (/usr/local/lib/node_modules/semantic-release-cli/src/lib/npm.js:51:21)\n at <anonymous>\n at process._tickCallback (internal/process/next_tick.js:188:7)' }
But I’m logged in to npm:
$ npm whoami
zeke
Second attempt works:
$ npx semantic-release-cli setup
? What is your npm registry? https://registry.npmjs.org/
? What is your npm username? zeke
? What is your GitHub username? zeke
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 29 (11 by maintainers)
Commits related to this issue
- fix: lower-case the npm username (#190) — committed to Jeff-Tian/cli by ap-tianjef 4 years ago
- fix: lower-case the npm username (#190) (#341) Co-authored-by: Jeff Tian <Jeff.Tian@externals.adidas.com> — committed to semantic-release/cli by Jeff-Tian 4 years ago
This should be fixed in
3.6.5
. Please let us know if the issue is indeed fixed.I’m new to semantic-release-cli and I sometimes get this issue. First time I ran setup it logged in fine but subsequent attempts kept failing then after a while, it seemed to work again. Here are my logs running the module with
npm_config_loglevel=verbose
:login failure
login success
It appears that on the first try, the response is sending back json data but on subsequent tries, it sends back compressed data and so the code @zeke linked is not extracting the token.
Update: Replacing https://github.com/semantic-release/cli/blob/45c00b42defee2f505dbcb1107699e0522c0155b/src/lib/npm.js#L45 with
seems to have fixed my issue.
could you send a pull request that lower-cases the username?
If you run your command with
yarn ...
, try running it withnpm ...
. This “solves” the issue for me.(I know this issue is closed but it comes up in the first results in google so adding this solution seems useful)
did that get resolved via https://github.com/semantic-release/cli/pull/238?
The problem come from the npm registry instability.
npm-registry-client
include a retry mechanism that was alleviating the network/server issues.It has been changed to handle 409 errors from some “compatible” registries in https://github.com/semantic-release/cli/commit/92e15f717b280bdbee186af7bda45d3749e47b56.
The solution would be to use a proper http client (personally I prefer https://github.com/sindresorhus/got) that would allow to use Promises, setup the authentication (token or user/pass/email) and handle the different errors. And we would need to add a retry mechanism with https://github.com/sindresorhus/p-retry.
Another solution would be to use
npm-registry-client
again and to promisify it with https://github.com/sindresorhus/pify so we can handle a callback with multiple arguments (err
,parsed
,raw
andresponse
) with multiargs.I would rather use https://github.com/sindresorhus/got rather than continuing to deal with the multiple issues and shortcomings of
npm-registry-client
(we had a bunch of problems with it in https://github.com/semantic-release/npm).From working on this #185 i saw that it always generates token at first, and then complain about not able to login, trying again immediately it should work, since the first try generates the token without you knowing
check https://github.com/theo4u/cli/blob/aac04906701889d4bb17b2ae75671bb2dea012ee/src/lib/npm.js#L46 i resolved it there instead of the
body
becauseparsed
returns the newly generated token@gr2m ^^
@simlu sorry that this frustrates you, but please be kind ❤️ we would appreciate if you could delete or edit your comment
Same here. How do you resolve this?
Edit: Nvm, just try again and again… 😃