lerna
lerna copied to clipboard
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 |
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.
Related #2619
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 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.
We're running into a similar problem where lerna is hanging on prepare-commit-msg , but (a) we're not running husky and (b) it's happening in the CI system (Jenkins), so CTRL-C isn't an option.
What's more confusing is, why is the prepare-commit-msg hook being called in a CI environment?
I'm really hoping for this fix as well because I can't publish without having to do HUSKY_SKIP_HOOKS=1. For now I guess i have to put these in the CI as an env.
@metasean @HanamDo-TF if you're trying to publish in CI, it could be attempting to make publish commits or version pumps
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 encountered the same issue, which is caused by running commitizen in git prepare-commit-msg hook.
After checking the hook's document (https://git-scm.com/docs/githooks#_prepare_commit_msg), I found a solution. In the prepare-commit-msg hook, first check the second parameter ($2) and see if it is 'message'. If it's 'message', this means git commit is invoked with "-m" option with a message, then DO NOT invoke commitizen, as git commit may be invoked in a script or by another program, such as lerna.
Then problem solved.
@bingtimren Could you share an example of this check ?
We have the same issue, and HUSKY_SKIP_HOOKS=1 does not seem to work.
@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".
@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 fiI'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".
it actually works for me, thx!
I had a similar issue (albeit with version) and I tracked it down through the Lerna code:
git remote update was being called - I needed to reauthenticate with Heroku.
Run the git remote update yourself to rule this out/get more info on what's happening.
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!
For me it is getting stucked at ....
? Are you sure you want to publish these packages? Yes
lerna info execute Skipping releases
I am invoking this command from local
I am trying to use github packages.after setting up packages configuration , when i am doing lerna publish then only its hangs. I have tried removing husky , the end result was same.
Without publish configuration , lerna is able to publish tags.
Tried everything from above
Any solution will be helpful 😺