lerna: Lerna hangs on publish

$ npx lerna publish

...
lerna info execute Skipping git push
lerna info execute Skipping releases

And it hangs there. It creates CHANGELOG.md files and increments the version, but the command never finishes

Possible Solution

npx lerna publish from-package

In this case it finishes in seconds, except it does not increment versions or create changelog.

Steps to Reproduce (for bugs)

Repo: https://github.com/katawaredev/config

lerna.json

{
  "packages": ["packages/*"],
  "version": "independent",
  "command": {
    "publish": {
      "conventionalCommits": true,
      "message": "chore(release): release"
    },
    "bootstrap": { "hoist": true },
    "version": { "push": false }
  }
}

Context

The packages in the monorepo were not published before. Running npx lerna publish after npx lerna publish from-package again never finishes.

I am using Verdaccio to publish them locally for testing.

Your Environment

Executable Version
lerna --version 3.22.1
npm --version 6.14.4
node --version 10.19.0
OS Version
Pop!_OS 20.04

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 8
  • Comments: 15

Most upvoted comments

Thanks, @hoangnm, disabling Husky seemed to solve my issue: HUSKY_SKIP_HOOKS=1 lerna publish

The question is: Is this behavior a bug, or it is supposed to happen (e.g. it’s husky’s fault)? If it’s not related to lerna, I’ll close it.

I ran into the same issue with these settings:

Environment

  • os ubuntu v18.04
  • node v14.15.4
  • npm v6.14.10

package.json

{
  "name": "workspace",
  "version": "1.0.0",
  "private": true,
  "devDependencies": {
    "@commitlint/cli": "^11.0.0",
    "@commitlint/config-conventional": "^11.0.0",
    "commitizen": "^4.2.2",
    "cz-conventional-changelog": "^3.3.0",
    "husky": "^4.3.7",
    "lerna": "^3.22.1",
    "markdownlint": "^0.22.0",
    "markdownlint-cli": "^0.26.0",
    ...
  },
  "scripts": {
    "ci": "<run the test suite>",
    "release": "lerna publish",
    ...
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  },
  "husky": {
    "hooks": {
      "pre-commit": "npm run ci",
      "prepare-commit-msg": "exec < /dev/tty && git cz --hook || true",
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  }
}

lerna.json

{
  "packages": [
    "packages/*"
  ],
  "version": "1.0.0-alpha.16",
  "command": {
    "publish": {
      "allowBranch": "main",
      "message": "chore(release): %s"
    }
  }
}

Workaround

I hit Ctrl + C just once and the process continues.

I got the same problem, then I found out it’s the prepare-commit-msg hook that prevents lerna to finish the git commit action.

@mderrien29 this is my “prepare-commit-msg” hook, it works for me

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

if [ "$2" != "message" ];then 
    exec < /dev/tty && node_modules/.bin/cz --hook "$1" "$2" "$3" || true
fi

I’m not an expert on shell script. If you are using POSIX sh instead of bash, the script may need to be changed. Anyway the point is to check $2 and skip commitizen if it’s “message”.

I see this as well and found a strange work around… just do CTRL+C (or whatever your terminal quit command is) just once, and the process resumes.

Hey folks, I’ve been fighting with this this the whole morning and finally I found a solution.

Seems that using the latest Husky version ( “husky”: “^6.0.0” ), if you want to skip hooks you need to use:

HUSKY=0

Instead of:

HUSKY_SKIP_HOOKS=1

https://typicode.github.io/husky/#/?id=with-env-variables

I’m also using cross-env to avoid isues with windows machines https://www.npmjs.com/package/cross-env

This is my npm script where I skip husky-precommit (commitizen), lerna generates the changelogs for all packages and everything works:

"version:release": "cross-env HUSKY=0 lerna version --force-publish --conventional-commits -m \"chore(release): publish %s\"",

This is the prepare-commit-msg husky hook:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

exec < /dev/tty && node_modules/.bin/cz --hook || true

And this is the result:

$ yarn version:release
yarn run v1.22.11
$ cross-env HUSKY=0 lerna version --force-publish --conventional-commits --no-commit-hooks
lerna notice cli v4.0.0
lerna info current version 0.0.0
lerna WARN force-publish all packages
lerna info Assuming all packages changed

Changes:
 - @project/app: 0.0.0 => 0.1.0 (private)
 - @project/components: 0.0.0 => 0.1.0

? Are you sure you want to create these versions? Yes
lerna info execute Skipping releases
lerna info git Pushing tags...
lerna success version finished
Done in 52.92s.

Before this fix, I was receiving this error due I was not skipping Husky:

lerna info execute Skipping releases
lerna ERR! Error: Command failed with exit code 1: git commit --no-verify -m v0.2.0
lerna ERR! .husky/prepare-commit-msg: line 4: /dev/tty: No such device or address
lerna ERR! husky - prepare-commit-msg hook exited with code 1 (error)

Hope it helps!