Skip to content

Lerna publish doesn't warn that no token is set #1347

Closed

Description

@edmorley

Expected Behavior

If publish is going to fail since no token set, then abort early to prevent the repository being left in a half-published state.

Current Behavior

If no token set, publish proceeds regardless, resulting in:

? Are you sure you want to publish the above changes? Yes
lerna info publish Publishing packages to npm...
lerna ERR! publish Retrying failed publish: @neutrinojs/chunk
lerna ERR! publish Retrying failed publish: @neutrinojs/babel-minify
lerna ERR! publish Retrying failed publish: @neutrinojs/clean
lerna ERR! publish Retrying failed publish: @neutrinojs/banner
lerna ERR! publish Retrying failed publish: @neutrinojs/banner
lerna ERR! publish Retrying failed publish: @neutrinojs/chunk
lerna ERR! publish Retrying failed publish: @neutrinojs/clean
lerna ERR! publish Retrying failed publish: @neutrinojs/babel-minify
lerna ERR! publish Retrying failed publish: @neutrinojs/banner
lerna ERR! publish Retrying failed publish: @neutrinojs/chunk
lerna ERR! publish Retrying failed publish: @neutrinojs/babel-minify
lerna ERR! publish Retrying failed publish: @neutrinojs/clean
lerna ERR! publish Retrying failed publish: @neutrinojs/banner
lerna ERR! publish Retrying failed publish: @neutrinojs/chunk
lerna ERR! publish Retrying failed publish: @neutrinojs/clean
lerna ERR! publish Retrying failed publish: @neutrinojs/babel-minify
lerna ERR! publish Ran out of retries while publishing @neutrinojs/banner Error: Command failed: yarn publish --tag latest --new-version 8.2.0
lerna ERR! publish error An unexpected error occurred: "No token found and can't prompt for login when running with --non-interactive.".
lerna ERR! publish [1/4] Bumping version...
lerna ERR! publish info Current version: 8.2.0
lerna ERR! publish [2/4] Logging in...
lerna ERR! publish info If you think this is a bug, please open a bug report with the information provided in "C:\\Users\\Ed\\src\
lerna ERR! publish eutrino-dev\\packages\\banner\\yarn-error.log".
lerna ERR! publish info Visit https://yarnpkg.com/en/docs/cli/publish for documentation about this command.
lerna ERR! publish
lerna ERR! publish     at Promise.all.then.arr (C:\Users\Ed\src\neutrino-dev\node_modules\lerna\node_modules\execa\index.js:236:11)
lerna ERR! publish     at <anonymous>
lerna ERR! publish     at process._tickCallback (internal/process/next_tick.js:118:7)
lerna ERR! execute callback with error
lerna ERR! Error: Command failed: yarn publish --tag latest --new-version 8.2.0
...

Possible Solution

If npm publishing is enabled (ie the user hasn't passed --skip-npm to lerna publish), then check to see whether a token is set, and if not, abort the publish before doing anything.

Steps to Reproduce (for bugs)

  1. Clear authentication tokens set in .npmrc / .yarnrc
  2. Run lerna publish in a repo that uses lerna
lerna.json

{
  "lerna": "2.4.0",
  "packages": [
    "packages/*"
  ],
  "version": "8.2.0",
  "gitRemote": "upstream",
  "npmClient": "yarn",
  "registry": "https://registry.npmjs.org/",
  "useWorkspaces": true
}

Context

I thought lerna publish would prompt me for a token, avoiding the need to save it to disk. However it doesn't, and left my local state half-published, meaning I'm not sure how to retry the publish without manually unpicking the changes.

Your Environment

Executable Version
lerna --version 2.9.0
npm --version 5.6.0
yarn --version 1.5.1
node --version 9.7.1
OS Version
NAME VERSION
Windows 10 1709

Activity

  1. evocateur commented on Mar 24, 2018

    @evocateur
    Member

    It's not lerna's responsibility to set a token, or even be aware of what that token is/where it is located. I agree we should probably run npm whoami (yarn equivalent ???) at the beginning of publish just so the inevitable error can be helpful/informative instead of damaging.

  2. edmorley commented on Apr 3, 2018

    @edmorley
    Author

    Hi! Yeah I agree it's not lerna's responsibility to handle setting the token; this issue was just about failing early to limit the damage it causes. I can't seem to find a yarn equivalent to npm whoami - perhaps lerna can just use npm whoami regardless of the value of npmClient?

  3. evocateur commented on Apr 3, 2018

    @evocateur
    Member

    I have a hunch yarn has different opinions about how to resolve registry authentication. No actual proof, just bitter experience of several yarn-related lerna bugs due to inconsistent implementation of registry patterns.

  4. b4lk0n commented on May 22, 2018

    @b4lk0n

    Faced a similar issue. Publishing anonymously to private registry (proget). When yarn publish works as expected, but lerna publish fails with "No token found and can't prompt for login when running with --non-interactive." error

  5. lock commented on Dec 27, 2018

    @lock

    This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  6. locked as resolved and limited conversation to collaborators on Dec 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions