commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

fix: Segmentation fault: 11 using [email protected] while using Husky commit-msg hook

Open doughlass opened this issue 2 years ago • 10 comments

Expected Behavior

I should be able to commit and Husky runs the commit-msg hook and lints the commit message.

Current Behavior

Unable to proceed to commit due to the following error:

.husky/commit-msg: line 4: 88256 Segmentation fault: 11  npx commitlint --edit ${1}
husky - commit-msg hook exited with code 139 (error)

My commit-msg file is as follows:

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

npx commitlint --edit ${1}

This is only in the past day I started to receive this error.

If I alter npx commitlint --edit ${1} to be npx [email protected] --edit ${1} I am asked by npx to install 17.3.0 and once installed the commitlint works as expected.

It seems to be since 17.4.0 was released.

Affected packages

  • [X] cli
  • [ ] core
  • [ ] prompt
  • [ ] config-angular

Possible Solution

If I change commit-msg to replace the npx command to node node_modules/@commitlint/cli/lib/cli.js --edit $1 I am able to run the commitlint against my message as my local is 17.4.0, it works as expected. Possibly an issue with npx?

Steps to Reproduce

1. Install Husky and Commitlint
2. Run `npx husky add .husky/commit-msg  'npx --no -- commitlint --edit ${1}'`
3. Edit a file, `git add .` and then try to commit a message. eg: `git commit -m "ugly. non-c
onventional commit message"`

Context

Unable to commit using commitlint

commitlint --version

@commitlint/[email protected]

git --version

2.39.0

node --version

v18.12.1

doughlass avatar Jan 05 '23 10:01 doughlass

Ugh, thanks.
Need to check but I think commitlint went from husky v8.0.1 to v8.0.3. Will try to find time and see if there's an issue.
If this is a general issue more people will roll in soon I guess. Lets' see.

escapedcat avatar Jan 05 '23 13:01 escapedcat

Ugh, thanks. Need to check but I think commitlint went from husky v8.0.1 to v8.0.3. Will try to find time and see if there's an issue. If this is a general issue more people will roll in soon I guess. Lets' see.

Sorry for raising it 😂

The workaround I have to change the file to read node node_modules/@commitlint/cli/lib/cli.js --edit $1 seems to work.

Hoping that you and the other collaborators can have an official solution for the npx command soon

doughlass avatar Jan 05 '23 18:01 doughlass

I added a duplicate issue #3518 but closed it

here are the details:

Expected Behavior

$ npx commitlint --edit

⧗   input: dfds
✖   subject may not be empty [subject-empty]
✖   type may not be empty [type-empty]
✖   Jira issue reference must be in the subject [jira-issue-reference-in-subject]

✖   found 3 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

Current Behavior

> [email protected] lint
> eslint "{src,apps,libs,test}/**/*.ts" --fix && npm run prettier:check


> [email protected] prettier:check
> prettier --check . --ignore-path .gitignore --ignore-unknown

Checking formatting...
All matched files use Prettier code style!
.husky/commit-msg: line 4: 76524 Segmentation fault: 11  npx commitlint --edit
husky - commit-msg hook exited with code 139 (error)

Affected packages

  • [X] cli
  • [ ] core
  • [ ] prompt
  • [ ] config-angular

Possible Solution

No response

Steps to Reproduce

https://github.com/conventional-changelog/commitlint#getting-started

Context

  • Mac 13.2 (22D49)
  • Apple M1 Pro
  • zsh 5.8.1 (x86_64-apple-darwin22.0)
  • "husky": "^8.0.3",
  • "@commitlint/config-conventional": "^17.4.2",
  • content of the failing hook
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx commitlint --edit

commitlint --version

@commitlint/[email protected]

git --version

git version 2.33.0

node --version

v18.13.0

Thanks!

Shereef avatar Feb 02 '23 23:02 Shereef

Same problem. I tried using husky both v8.0.0 and v8.0.3 but no success. I tried to set up this with using yarn I have two commands in pre-commit file.

  1. npx pretty-quick --staged → this works fine, see logs below and other commands too like npm -v, echo
  2. npx eslint . → this does not work (but works without husky)

logs

🔍  Finding changed files since git revision f78a10a.
🎯  Found 0 changed files.
✅  Everything is awesome!
.husky/pre-commit: line 5: 53058 Segmentation fault: 11  npx eslint .
husky - pre-commit hook exited with code 139 (error)
Completed with errors, see above

.husky/pre-commit

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

npx pretty-quick --staged
npx eslint .

I am using MacBook Pro with Chip: Apple M1 Max

AnilBairi avatar Mar 09 '23 15:03 AnilBairi

try using a different version of node, for example 16.19.0, it helped me

fothdr avatar Apr 04 '23 11:04 fothdr

According to latest comment this can be fixed by using a newer node version

escapedcat avatar Oct 20 '23 14:10 escapedcat

I was using 18.13.0 as stated above The original poster was using 18 too

Shereef avatar Oct 20 '23 14:10 Shereef

I was using 18.13.0 as stated above The original poster was using 18 too

Ah thanks, sorry

escapedcat avatar Oct 20 '23 14:10 escapedcat

Had this issue for a while now until I stumbled with this issue and read through the comments, can confirm upgrading the node version to 20.11.1 solved this for me.

ozavraham avatar Mar 18 '24 09:03 ozavraham