husky icon indicating copy to clipboard operation
husky copied to clipboard

husky with sourcetree : Can't find node in PATH, trying to find a node binary on your system

Open zhaozhe0831 opened this issue 8 years ago • 41 comments

I'm trying to use husky precommit with sourcetree. The precommit command is run but i get the following error:

image

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

image

zhaozhe0831 avatar Oct 31 '18 08:10 zhaozhe0831

same issue here after upgrading node to v10.13

screen shot 2018-11-02 at 09 24 09

haithemT avatar Nov 02 '18 08:11 haithemT

@zhaozhe0831 I have same problem when I switch node version to 8.12.0 with n.

zhaozhe0831 avatar Nov 08 '18 10:11 zhaozhe0831

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

typicode avatar Nov 08 '18 11:11 typicode

This is an error. If I get this: image 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.

mdversion01 avatar Mar 22 '19 22:03 mdversion01

You need to set your system-wide node version to 8 or higher:

nvm alias default 8

fabb avatar Mar 23 '19 07:03 fabb

my default is

default -> 8 (-> v8.11.3)

But I still get the same thing above when trying to commit with Sourcetree.

mdversion01 avatar Mar 23 '19 12:03 mdversion01

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

mdversion01 avatar Mar 23 '19 13:03 mdversion01

In my MAC, I fixed this by:

  1. Check Node path:
which node
/usr/local/bin/node
  1. Update ~/.bash_profile:
# ...
export PATH="/usr/local/bin:$PATH"

thoqbk avatar Aug 29 '19 06:08 thoqbk

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

bitclaw avatar Oct 17 '19 21:10 bitclaw

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?

spacecakes avatar Oct 21 '19 10:10 spacecakes

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 avatar Oct 24 '19 10:10 sainnr

@sainnr solution worked for me on Catalina/zsh

zkrige avatar Oct 31 '19 08:10 zkrige

The last one works for me as well

valeriopisapia avatar Nov 05 '19 08:11 valeriopisapia

thank you @sainnr

crgeee avatar Nov 12 '19 18:11 crgeee

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

a1isaeed avatar Dec 19 '19 21:12 a1isaeed

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. image Then from your terminal run stree it works for me!

crespowang avatar Jan 22 '20 04:01 crespowang

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.

alexilyaev avatar Jan 30 '20 15:01 alexilyaev

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

ogelacinyc avatar Mar 10 '20 08:03 ogelacinyc

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"

bobrosoft avatar May 18 '20 09:05 bobrosoft

Switching to husky 3.1.0 (which uses run-node) also worked for me

https://github.com/typicode/husky/issues/639

tenadolanter avatar Jun 12 '20 10:06 tenadolanter