husky: Can't find Node.js installed with NVM, when used in VS Code
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.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 7
- Comments: 15 (2 by maintainers)
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!
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.Adding the
~/.huskyrc
worked for me. Thanks @rhefnerIs there anywhere a a guide how to make husky work when used in nvm / vscode environment?
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
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