I have a project with a Husky git pre-commit hook:
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
yarn lint-staged
If I commit from Terminal, the hook and commit work fine.
If I try to commit from VSC, I get error:
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
/usr/bin/env: ‘node’: No such file or directory
husky - pre-commit hook exited with code 127 (error)
husky - command not found in PATH=/usr/lib/git-core:/home/myname/.cargo/bin:/home/myname/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
So I've been trying to figure out why VSC seems unaware of nvm and where the current node executable is.
My ~/.bashrc
calls source ~/code/.bashrc_extra
, which includes:
echo $0
which bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm current
node -v
When I open Terminal, I see:
bash
/usr/bin/bash
/home/myname/.nvm/versions/node/v18.18.2/bin/node
v18.18.2
v18.18.2
So, everything in Terminal is fine, so it makes sense that it works there.
When I open a VSC terminal, I see those same values except /usr/bin/bash
instead of bash
.
How can I fix my setup so that the pre-commit hook will work?
- VSC 1.84.2
- Ubuntu 22.04.3