GitKraken hook fails with error NPX does not exist in path

Author: Steven Neiland
Published:

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.

Solution

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.

# ~/.huskyrc
export NVM_DIR="$HOME/.nvm"
[ -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.

What Do You Think?

Reader Comments

Comment Etiquette:

  • Please keep comments on-topic.
  • Please do not post unrelated questions or large chunks of code.
  • Please do not engage in flaming/abusive behaviour.
  • Comments that contain or appear to be advertisments, will not be published.
  • Comments that appear to be created for the purpose of linkbuilding to commercial sites will be removed.
*
*



Archives Blog Listing