lerna: Recover from failed publish

I lost connectivity during lerna publish and some packages got lerna-temp published and other not. Now I have a dirty tree were lerna publish fails with:

$ lerna publish
Lerna v2.0.0-beta.30
Independent Versioning Mode
Checking for updated packages...
Errored while running PublishCommand.initialize
Error: No updated packages to publish.
    at PublishCommand.initialize (/usr/local/lib/node_modules/lerna/lib/commands/PublishCommand.js:94:18)
    at PublishCommand._attempt (/usr/local/lib/node_modules/lerna/lib/Command.js:161:21)
    at PublishCommand.runCommand (/usr/local/lib/node_modules/lerna/lib/Command.js:145:12)
    at PublishCommand.run (/usr/local/lib/node_modules/lerna/lib/Command.js:69:12)
    at Object.<anonymous> (/usr/local/lib/node_modules/lerna/bin/lerna.js:58:11)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)

How can I recover from this?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 20
  • Comments: 18 (3 by maintainers)

Most upvoted comments

That would be my vote too. I don’t think the “Publish” commit or tag should be pushed if the NPMs don’t publish.

I just got bit by a similar issue. lerna publish failed because one of my scoped packages was not yet published with --access=public so npm rejected the publish. After correcting that, lerna thinks there is nothing updated to publish, but none of the npm tags have yet been updated.

It would be awesome if lerna could retry a publish after failing.

I always get this issue when I forget to npm login before publishing new public packages

The way I fixed this issue is as follows:

  1. Uncommit from the local repo and tag.

    git reset --hard HEAD^
    git tag -d v1.0.0
    
  2. Remove the last commit and tag in the remote (Github) pushed by Lerna.

    git push origin +HEAD
    git push --delete origin v1.0.0
    
  3. Retry lerna publish

    lerna publish
    

When publishing to the registry fails, is it possible to not only not push the “Publish” commit, but to revert the commit and delete the tags? Or just not take these steps until the packages have been successfully published?

I don’t know the Lerna’s code base, but it seems so trivial of a change to just delay the git push to the last step. It’s quite simple to revert all other Git changes manually (deleting tags and resetting to previous commit), but once tags are pushed, it can be really hard to delete them (someone else may have already fetched them and they have to manually delete them as well).

Anyway, at least there’s the hidden --no-push option (it’s not in the publish help, but it works), so I’m using lerna publish --no-push && git push --tags.

I’ve seen in other issues suggestions to use from-package to just retry without having to undo anything on Git, but, if I understand well, that only works if the issue was temporary, not if there was a bug in your code preventing the publishing to work (e.g. a mistake in some package.json that only affects the publish command), because that requires a new commit to fix it, and therefore you normally don’t want leave the wrong tags the repository.

Hi Folks 👋

As you may have seen in our published roadmap for Lerna v7 here: https://github.com/lerna/lerna/discussions/3410 recoverable publish is a priority for us in this current phase of work.

I am going to close any duplicate issues in this area and point them here. As a lerna user myself I’m excited to land this!

Many thanks 🙏

I ran into this issue as well where my lerna publish failed due to some issue with our repository but the tags were created and now i am not able to republish that since it says no updated packages to publish

lerna info Checking for prereleased packages… lerna info No updated packages to publish.

what is the solution for this? how can i republish already created tags by lerna

Hi again, delighted to say that this capability is already available in the latest lerna (6.5.1 at the time of writing) thanks to #3513

Please upgrade to the latest and you should not run into republishing issues again.

Many thanks!

I had the same issue: I’ve added new package, but when I wanted to publish it, npm publish failed with “You should confirm your email before publishing new package” and after that I can’t publish new version.

I had version 0.0.13, started update to 0.0.14 with lerna, but after this fail I see vundefined tag was created, but no v0.0.14. I tried to create v0.0.14 tag manually, git pull --tags, but after running lerna publish I see vundefined again. After that I deleted tag vundefined, git describe --abbrev=0 --tags correctly shows last tag, but lerna publish says:

? Select a new version (currently undefined) (Use arrow keys)
❯ Patch (null)
  Minor (null)
  Major (null)
  Prepatch (null)
  Preminor (null)
  Premajor (null)
  Prerelease
  Custom

Any thoughts how to fix it?

UPD: fixed it with publishing custom version, but anyway “current” version in this case determined incorrectly

I had a lerna publish error because of a wrong configured .npmrc In my case I had to (fix my npmrc first and then) go through all my packages and and execute manually npm publish --ignore-scripts <packagename.tgz> (tgz files where already created by lerna publish)

I ran into this as well today (a yarn token issue mentioned in #1347). To my future self 😄:

Confirm publishing state (no commits had been pushed yet):

~/d/o/puppeteer-extra git:master ❯❯❯ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean

~/d/o/puppeteer-extra git:master ❯❯❯ git log
commit 603032ec35b16a6eb60a9940cb0801de78fef9bb
Date:   Sat Aug 18 19:47:52 2018 +0200

    Publish

     - puppeteer-extra-plugin-anonymize-ua@2.0.8
     - puppeteer-extra-plugin-block-resources@2.0.9
     (...)

~/d/o/puppeteer-extra git:master ❯❯❯ git describe --abbrev=0 --tags
puppeteer-extra-plugin-devtools@2.0.9

Revert failed publish (doesn’t reset tags, only the last commit):

~/d/o/puppeteer-extra git:master ❯❯❯ git reset --hard HEAD^
HEAD is now at c7537d0 Update docs

Confirm and fix yarn / npm issue:

❯❯❯ yarn login
yarn login v1.7.0
info npm username: berstend

❯❯❯ npm whoami
npm ERR! code E401

❯❯❯ npm login
Username: berstend

❯❯❯ npm whoami
berstend

Upgrade lerna (i was still on 2.11.0 and 3.1.1 handles publishing errors better):

~/d/o/puppeteer-extra git:master ❯❯❯ yarn add lerna --ignore-workspace-root-check --dev

Modify lerna.json to use npm instead of yarn as registry client (it just wouldn’t work with yarn):

  "npmClient": "npm",
  "registry": "https://registry.npmjs.org/",

… and finally run lerna publish two times (one for good measure and one due to existing tags).

Whew!

The yarn error I was hitting (for google fu):

lerna ERR! publish error No token found and can't prompt for login when running with --non-interactive.