Closed
Description
Husky stopped working in VS Code (latest) after I installed node.js (LTS) with node version manager on Ubuntu 18.4. But it works perfectly in the terminal.
$ type node
node is /home/nikhil/.nvm/versions/node/v10.15.0/bin/node
It is unable to find node.js
and shows the following error in the Git Output
inside VS Code integrated terminal
:
Can't find node in PATH, trying to find a node binary on your system
Couldn't find the Node.js binary. Ensure you have Node.js installed. Open an issue on https://github.com/sindresorhus/run-node
What should I do?
NOTE: In VS Code, Husky was working fine when nodejs was installed with sudo in priviledged location.
Activity
rhefner commentedon Jan 31, 2019
Seeing the same thing. Executing a commit manually, husky gets involved and works as intended. Executing a commit via VS Code, it fails:
I tried
pre-commit
before husky, which worked. But, figured that husky supports so much more and is popular, so I would try it instead.rhefner commentedon Jan 31, 2019
Ah, just saw #282 as well.
rhefner commentedon Jan 31, 2019
Looks like adding a
~/.huskyrc
file with:Stops VS Code from committing and allows husky to continue, but
run-node
still spits out one error message and VS Code will use that error as it's display: "Git: Can't find node in PATH, trying to find a node binary on your system" ... But, gives you a chance to open the Git log and you can see that Husky did indeed run:...Least it still works. IF someone has a better solution, would love to hear it. This is just a hack!
brandon-pereira commentedon May 23, 2019
Adding the
~/.huskyrc
worked for me. Thanks @rhefnerphifa commentedon Jun 27, 2019
Is there anywhere a a guide how to make husky work when used in nvm / vscode environment?
typicode commentedon Jun 27, 2019
@phifa https://github.com/typicode/husky/blob/master/DOCS.md#huskyrc should do the trick
phifa commentedon Jun 27, 2019
It looks like it works... I am getting this message, when opening the log I see the eslint errors from husky. Is this how it's supposed to work?
jcollum-autodesk commentedon Sep 18, 2019
@phifa sounds right to me, eslint errors means you ... have eslint errors
gabrielmicko commentedon Sep 23, 2019
What worked for me is creating
~/.huskyrc
and defining node path.rfgamaral commentedon Oct 25, 2019
How exactly did you do that?
typicode commentedon Jan 7, 2020
Closing to clean up. Feel free to create another issue if you still have problems.
thasmo commentedon Mar 27, 2020
The only proper solution I found was to create a
~/.huskyrc
file, as mentioned in the husky docs:I added
nvm use
so it will load the actual node version defined in the project's.nvmrc
file.icetbr commentedon May 7, 2020
As an alternate solution, this at least gives a proper error message on hook fail
sudo ln -s -f `npm config get prefix`/bin/node /usr/bin/node
Zeal29 commentedon Sep 29, 2020
nvm + husky + VS Code source control = is not working for me but I fixed it.
What worked of me is (I am not an expert something might optional you can see, but they make my project working with VS Code source control)
nvm use --delete-prefix v14.12.0
<- use then node version you want to usenvm use v14.12.0
open ~/.huskyrc
if file dont exit create it withtouch ~/.huskyrc
6.(optional) add these 2 lines in you ~/.bash_profile if still not working because I added and too lazy to remove them
Thlnking commentedon Mar 11, 2022
Adding the ~/.huskyrc worked for me too. Thanks @rhefner