Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.
Yesterday a co-worker ran into a problem where GitKraken was failing to execute our husky pre-commit hooks. Since they run virtually the same configuration of Ubuntu as I do I offered to help take a look.
For a while we were really stumped since npx was definitely installed and doing a commit from the command line ran the hooks without issue. Eventually I stumbled on a stack overflow thread that mentioned a similar issue with another GUI tool and node version managers. On further research I learned that, to quote the internet:
Node version managers such as NVM work by modifying the PATH when the terminal is started. For this reason GUI clients usually don't work well with version managers as they don't call source on .bashrc or .zshrc where these version managers are usually initialized.
In this case the issue for us related specifically to husky so the solution we found was to create a .huskyrc file that exported the nvm directory. To do this we created the file in the home directory with the following content found here.
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
No sooner had we done this then the hooks started working. I imagine that other GUI tools would utilize a similar solution.