0

I have a precommit hook with this content

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint

This hook runs whenever I try to commit changes.

For a few days now, I get the error "npm command not found" every time I try to commit directly in VS Code's source control box but not when I manually run the git commit command in the integrated terminal.

For context, I use ZSH as the default terminal on my Mac and use NVM for managing node versions between projects.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Make sure that (1) npm is still installed, and (2) your shell's path—that would be `/bin/sh`'s path because your hook is run by `/bin/sh`, per the first line of the hook file—includes the directory in which npm is installed, so that the shell can find the `npm` command to run it. (Since this works from the Git command line, the problem is specifically the path as supplied by VSC. You'll need to find out how to control that.) – torek Apr 26 '22 at 20:28
  • Thanks @torek, I found the answer in another post here: https://stackoverflow.com/a/72279243/5798407 – Abeeb 聖徒 Ola Jun 01 '22 at 15:43
  • @torek yes it does. It was basically the same problem. – Abeeb 聖徒 Ola Jun 01 '22 at 18:17
  • Just a side note: the "does this answer your question" link is auto-inserted by the "close as duplicate" button... then it goes away once the question *is* closed as a duplicate. The point of leaving a duplicate in place is to help others later searching for the same problem: sometimes the search only turns up the "duplicate" question, not the original. – torek Jun 02 '22 at 12:35

0 Answers0