lerna: Fails on npm publish leaves the repository on a inconsistent state

Hello,

When you do lerna publish, several good things happens:

  • Version is bumped on modified packages
  • Github tags are added and committed
  • Packages are published to npm

If this last step fails, then you are not able to republish the packages you were trying to publish. If you run lerna publish again, it raises an error about no packages has changed. You have to go to each package manually and run npm publish.

Is there any better approach? Regards

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 8
  • Comments: 17 (11 by maintainers)

Most upvoted comments

@noherczeg I have re-read my answer and it was not very polite. I take for granted that every answer has good intention. It was my fault to answer you so impolitely, and I’m sorry about it. Please accept my apologies.

I’ve faced the same issue several times. The problems are that after a failed npm publish:

  1. lerna doesn’t handle the errors properly, they all just get logged in a very verbose way and lerna exits
  2. you’re left with a publish commit and a set of tags that haven’t been pushed to git, but which prevent lerna from progressing with a publish

Ideally, lerna would delete the publish commit and all the tags, allowing the publish step to be run again. OR it would have an option to continue from where it failed before.

However, in the meantime you can use this:

# delete the latest commit
git reset --hard HEAD~1
# delete the latest batch of tags
git tag -d $(git log --date-order --tags --simplify-by-decoration --pretty=format:'%d' | head -1 | tr -d '()' | sed 's/,* tag://g')

lerna publish from-git will restart the publish if the previous execution pushed upstream successfully but then failed during the upload to the registry. YMMV.