close

[Solved] Committing fails in Git hooks pre-commit because the node command wasn’t found

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Committing fails in Git hooks pre-commit because the node command wasn’t found in java. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Committing fails in Git hooks pre-commit because the node command wasn’t found Error Occurs?

Today I get the following error Committing fails in Git hooks pre-commit because the node command wasn’t found in java.

How To Solve Committing fails in Git hooks pre-commit because the node command wasn’t found Error ?

  1. How To Solve Committing fails in Git hooks pre-commit because the node command wasn't found Error ?

    To Solve Committing fails in Git hooks pre-commit because the node command wasn't found Error Hooks are usually run with a very restricted $PATH; e.g. /bin:/usr/bin.

  2. Committing fails in Git hooks pre-commit because the node command wasn't found

    To Solve Committing fails in Git hooks pre-commit because the node command wasn't found Error Hooks are usually run with a very restricted $PATH; e.g. /bin:/usr/bin.

Solution 1

As @Stephen Savitzky suggested, it might be Node installation problem. However, if you’re able to

  1. Run application normally without an issue, and also
  2. See no issues when doing git commits from terminal

Then, it’s probably Node sourcing problem since the paths to it might be different from terminals or from GUI apps like VSC.

Your setup seems to be using husky for pre-commit hooks, so to ensure you have the right Node version, you could add ~/.huskyrc as suggested in the docs:

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

Then, you can source Node from NVM (if you use one) or another source. It’s also a good way to debug what’s actually going on when husky hook scripts kick in.

Solution 2

“node: command not found” means that there is no program called node on any of the directories in $PATH, the environment variable that tells the shell where to look for programs. Hooks are usually run with a very restricted $PATH; e.g. /bin:/usr/bin.

The best way to deal with this is to use an absolute path for any programs that aren’t installed in either /bin or /usr/bin. You can find out what path to use with the which command:

> which node
/home/steve/.nvm/versions/node/v10.6.0/bin/node

Of course, it’s also possible that node isn’t installed at all on the machine the hook is running on.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment