After I click Push in source tree, husky will run npm test
and fail. I can find the message, 'husky > pre-push (node v17.9.0)'. So the node version is v17.9.0. I run unit test in my terminal which node version is v14.19.3 and succeed. How can I change the node version in my source tree or just change node version for husky? I use nvm to switch the node version, none of them is v17.9.0.
Asked
Active
Viewed 1,377 times
0

Anthony Wang
- 93
- 1
- 1
- 10
-
Do you get the same errors when you push without Sourcetree? – jabaa Jun 06 '22 at 11:31
-
No, it work well in command line. And the node version in terminal is V14.19.3. – Anthony Wang Jun 07 '22 at 06:01
2 Answers
1
Because I use nvm, and source tree doesn't import node version in nvm. So I input some code in ~/.huskyrc.
# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm
If you use zsh, just change some code
# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

Anthony Wang
- 93
- 1
- 1
- 10
-2
you need to use this
nvm use 14.19.3
note that you need to run this command as an administrator

anaszarqawi
- 1
- 3
-
How to run this command as an administrator in source tree ? It doesn't work when I add sudo. – Anthony Wang Jun 06 '22 at 13:03