GitKraken hook fails with error NPX does not exist in path

Author: Steven Neiland

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.

# ~/.huskyrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/" ] && \. "$NVM_DIR/"

No sooner had we done this then the hooks started working. I imagine that other GUI tools would utilize a similar solution.

Reader Comments

  • 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 advertisments or appear to be created for the purpose of link building, will not be published.

Archives Blog Listing