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

We Are Going To Discuss About Committing fails in Git hooks pre-commit because the node command wasn’t found. So lets Start this Java Article.

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

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

    As @Stephen Savitzky suggested, it might be Node installation problem. However, if you're able to
    Run application normally without an issue, and also
    See no issues when doing git commits from terminal

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

    As @Stephen Savitzky suggested, it might be Node installation problem. However, if you're able to
    Run application normally without an issue, and also
    See no issues when doing git commits from terminal

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.

Original Author Of This Content

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.

Original Author Of This Content

Solution 3

You can add new entry to the Windows PATH environment variable using the Command Prompt as follows:

SET PATH=C:\Program Files\Nodejs;%PATH%

npm

Or you can set the PATH variable by using Windows graphical UI. (Annoying for me :/ )

Original Author Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment