2

I am setting up a precommit hook on an existing electron project (on Windows) using Husky (7.0.0). To install Husky I followed the documentation (here) and the .husky folder was correctly created with the two files: husky.sh

#!/bin/sh if [ -z "$husky_skip_init" ]; then debug () { if [ "$HUSKY_DEBUG" = "1" ]; then echo "husky (debug) - $1" fi } readonly hook_name="$(basename "$0")" debug "starting $hook_name..." if [ "$HUSKY" = "0" ]; then debug "HUSKY env variable is set to 0, skipping hook" exit 0 fi if [ -f ~/.huskyrc ]; then debug "sourcing ~/.huskyrc" . ~/.huskyrc fi export readonly husky_skip_init=1 sh -e "$0" "$@" exitCode="$?" if [ $exitCode != 0 ]; then echo "husky - $hook_name hook exited with code $exitCode (error)" fi exit $exitCode fi 

and pre-commit:

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

So now before commiting the test script should be run (the test script consists just in running jest, i.e. "test":"jest"). But when I run git commit (from terminal) it fails with this output: console output. The error message states that git is not able to find node, but what it looks really strange are the first two lines of the ouput, which are suggesting that jest actually run. I am using node 18.0.0 (managed via nvm-windows) and npm 7.24.2 (these two are confirmed both in windows terminal and in git bash). The path to node is already in my $PATH environment variable. Please let me know if I can add any detail

2 Answers 2

2

I found my problem, I had a double quotes in my environment variables list that was invalidating all the following paths (among which there was the nodejs path). To understand this thing I manually ran the commands thorugh the git bash and listed the PATH env variable. Anyway there is still something that I am not able to understand, in the git bash if i ran npm -v it showed the correct node version, but trying to run other commands caused error

Sign up to request clarification or add additional context in comments.

Comments

1

That was reported before (typicode/husky issue 980), referring to the "Command not found" documentation

If your ~/.huskyrc content is correct, the path should be set.

Check that be replacing, in your pre-commit, npm test by echo $Path (inspired by issue 462).

3 Comments

echoing $PATH in the commit script shows something slightly different then echoing $Env:PATH from the windows terminal. Anyway I can see in both results the entry C/Program Files/nodejs, so I would expect the node command to be recognized
@nicFlower OK so the issue are the double-quotes. "node" is not recognized. node would. Try in your pre-commit hook, to use the env command, in order to display all environment variables. Check if one includes as its value a "node".
that is the same idea I have, those quotes are messing everything up. Anyway I tried adding that env command in the precommit hook (in my .husky folder) and I can not see any "node" entry. I also tried to run the command from the git bash (C:\Program Files\Git\bin) but the result is the same

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.