GitKraken hook fails with error NPX does not exist in path

Author: Steven Neiland
Published:

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.

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.

Reader Comments

Fredrik L's Gravatar
Fredrik L
Friday, August 26, 2022 at 1:55:03 PM Coordinated Universal Time

This is still relevant (August 2022) and saved me from going home on a Friday with this problem unsolved. Now I can spend my weekend (mostly) not thinking about work! Thanks!

  • 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