On Windows, Husky pre-commit hooks fail with the following error message:
/usr/bin/env: 'bash': No such file or directory
husky - pre-commit hook exited with code 127 (error)
husky - command not found in PATH=/mingw64/libexec/git-core:/mingw64/bin:/usr/bin:/cmd:/mingw64/bin:/usr/bin
However my commit hook only runs a npm
command that does not involve bash. Why is this command looking for bash
and failing to do so?
Husky hooks are executed with
sh
rather thancmd
, even on Windows. If the hook contains anpm
command, it will try to executenpm.sh
(e.g.C:\Program Files\nodejs\npm
) rather thannpm.cmd
from the same folder.This
C:\Program Files\nodejs\npm
script relies on bash, as shown in the shebang line:If you are using a stripped down installation of Git that does not include
bash
such as MinGit (widely used in CI), you might get the error above. In this case, you might want to use the complete Git for Windows to includebash
. Else you need to modify your Git hooks to be Windows-compliant.