husky with sourcetree : Can't find node in PATH, trying to find a node binary on your system
I'm trying to use husky precommit with sourcetree. The precommit command is run but i get the following error:

Does anybody know what's wrong? I'm using n.
OS: macOS Mojave 10.14
Node: 10.13
$ which node: /usr/local/bin/node
npm: 6.4.1
$ whick npm: /usr/local/bin/npm

same issue here after upgrading node to v10.13

@zhaozhe0831 I have same problem when I switch node version to 8.12.0 with n.
It's actually not an error, just an information message. But it may sound like an error, especially as the output is red.
Node version managers works by modifying the PATH when the terminal is started. GUI clients usually don't work well with version managers as they don't source .bashrc or .zshrc where version managers are usually initialized.
So this message is just to let you know that husky will go into a mode where it'll try to find a Node binary (it uses run-node for that).
Here's more documentation https://github.com/typicode/husky/blob/master/DOCS.md#node-version-management
This is an error. If I get this:
in Sourcetree, it's doesn't commit.
Has anyone figured out a solution?
My message is different
Can't find node in PATH, trying to find a node binary on your system
husky > pre-commit (node v6.9.2)
lint-staged requires at least version 8.6.0 of Node, please upgrade
husky > pre-commit hook failed (add --no-verify to bypass)
but I using nvm and I have node 8.11.3 running.
You need to set your system-wide node version to 8 or higher:
nvm alias default 8
my default is
default -> 8 (-> v8.11.3)
But I still get the same thing above when trying to commit with Sourcetree.
I found somewhat of a reason/solution for the issue with Sourcetree. All of my dependencies are current, node, husky, lint-staged and no solution works but this,
https://stackoverflow.com/questions/52754063/git-push-failed-due-to-husky-pre-push-on-sourcetree
In my MAC, I fixed this by:
- Check Node path:
which node
/usr/local/bin/node
- Update
~/.bash_profile:
# ...
export PATH="/usr/local/bin:$PATH"
I had the same issue with Webstorm. If anyone is using fnm, then the command to fix it would be:
fnm default 12.10.0
This happens to me in Visual Studio Code if there's an linting error in the code, which we take care of in the pre-commit hook using eslint. vscode will display
Info: can't find node in PATH, trying to find a node binary on your system
in a pop up, even though it isn't the actual error, making it confusing for people to see what the real problem is (unless they check the output log).
If the commit goes through, there's no popup. Does anyone have an idea how I can get vscode to display the actual error instead of this?
I was experiencing this error with NVM & WebStorm (while everything was fine from the Ubuntu terminal).
In a nutshell, it's just a path problem with NPM & GUI vs terminal as @typicode suggests. In my case, I ended up configuring ~/.huskyrc as suggested in docs, to make sure it effectively uses NVM:
# ~/.huskyrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
@sainnr solution worked for me on Catalina/zsh
The last one works for me as well
thank you @sainnr
on my mac Mojave, I fixed this by:
Check Node path:
which node
/usr/local/bin/node
Add this path to the globals PATHs:
sudo vi /etc/paths.d/local_bin
enter edit mode by typing i then type this into the file:
/usr/local/bin
and save it esc wq enter
I have the same problem, then I launched SourceTree from terminal, then it worked! First you need to make sure you have stree cli installed.
Then from your terminal run stree it works for me!
I opened a related issue on the SourceTree Jira: https://jira.atlassian.com/browse/SRCTREE-7184
Basically the same issue with the PATH not including /usr/local/bin.
Please up vote.
It works for me. My machine is macOS mojave 10.14.6(18G2022) I use bash shell.
# ~/.huskyrc
export PATH="/usr/local/bin/:$PATH"
$ which node
/usr/local/bin/node
v13.8.0
$ which yarn
/usr/local/bin/yarn
1.22.0
If you're using macOS and NVM, then that's the proper solution: just create .huskyrc in your ~ home directory with next content:
#!/usr/bin/env bash
source ~/.bash_profile
if test -f ".nvmrc"; then
nvm use
fi
NOTE: it using your .bash_profile where NVM initialization should be already defined earlier when you installed NVM. I.e. next should be there already:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Switching to husky 3.1.0 (which uses run-node) also worked for me
https://github.com/typicode/husky/issues/639