June 28, 2023
Recently started trying out the macOS git client Fork as a replacement for GitKraken. GitKraken started out as simple and intuitive git GUI client but over the years it has unfortunately become unstable and filled with features catering to enterprise customers.
Points in favour of Fork:
However, an error occurred during the first commit in a project that utilizes Prettier for automatic code formatting, in combination with Husky and lint-staged, which ensures no unformatted code can be committed.
Git Error. An unexpected error occurred while performing the git request. Error details:
$ git commit --file=/var/folders/hd/xxx/T/yyy
.husky/pre-commit: line 4: npx: command not found
husky - pre-commit hook exited with code 127 (error)
husky - command not found in PATH=/Applications/Fork.app/Contents/Resources/git-instance/libexec/git-core:/Applications/Fork.app/Contents/Resources/git-instance/git-lfs:/Applications/Fork.app/Contents/Resources/gitflow-avh:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
What seems to be happening is that npx was not available in the context when the Husky pre-commit hook ran. It seems that Fork does not source the default shell of the operating system by design.
On the specific system in question asdf is used to manage the Node
version using the ZSH & Git install method. That involves
sourcing asdf in the file ~/.zshrc
. One way to fix the missing npx Fork git
error is to source asdf in the global Husky configuration file ~/.huskyrc
the same way by adding the following line:
# File: ~/.huskyrc
. "$HOME/.asdf/asdf.sh"
This assumes a asdf installation via ZSH & Git. The content will need to be modified depending on the asdf installation method. A similar approach would be used for nvm but the content would be different. Alternative approaches have also been proposed in this Fork issue on the matter.