Unable to git commit
Asked Answered
C

5

8

When I commit, I get the following husky error.

I ran npx --version to see if npx was installed.
It showed 8.0.0.
After running rm -rf .husky, I did another git commit, but it didn't solve the problem.

error

.husky/pre-commit: line 4: npx: command not found
husky - pre-commit hook exited with code 127 (error)
Chiton answered 9/11, 2021 at 13:6 Comment(7)
Does your pre-commit hook specify the full path to npx?Mafalda
Not specified. I use sourcetree to do git operations.Chiton
Is your terminal configured so that it knows the path to npx, but SourceTree might not be?Mafalda
Where can I see the npx settings?Chiton
I think I can solve this problem by writing the npx path in the ~/.huskyrc file, but I don't know how to open the ~/.huskyrc file.Chiton
For me, the problem was that my code really had lint errors (I set up pre-commit to run lint). However, instead of showing a log or message, I got husky - pre-commit hook exited with code 127 (error). Probably because of wrong configuration.Fleawort
git commit -m "message" --no-verifyAcetylide
C
8

npx husky-init npm install

enter image description here

npm run prepare

Castillo answered 14/11, 2021 at 16:18 Comment(1)
Please don't post screenshots of text. They can't be searched or copied, or even consumed by users of adaptive technologies like screen readers. Instead, paste the code as text directly into your question. If you select it and click the {} button or Ctrl+K the code block will be indented by four spaces, which will cause it to be rendered as code.Oleum
I
1

For me this is caused by missing Git path in Advanced System Settings > Environment Variables > System Variables > Path

The missing value is one of

C:\Program Files\Git\cmd
C:\Program Files\Git\bin

Add this and then restart your Git environment. This is from a comment at the bottom of this thread https://github.com/typicode/husky/issues/1038

This happens to me in Visual Studio, usually after an update this is missing and needs to be re-added.

Interjacent answered 22/5, 2023 at 17:34 Comment(0)
S
0

This is the vendor's answer to this issue:

But if you don't want to spend time reading Husky docs, and if you are using nvm for using multiple versions of Node, every time you open a new terminal tell it which Node version you want to use. It means in the terminal of your git cli (where you "git commit ..."), do:

nvm use 12.12.12 (With your desired Node version of course)

Sigil answered 6/6, 2022 at 9:37 Comment(0)
J
0

For me, none of the solutions here worked. I had to reinstall Node.js. I didn't download it via the CLI, but rather the official site: https://nodejs.org/en/download/

Not sure if that makes a difference but that's how I downloaded & fixed it. I hope it can help someone else out too!

Jacob answered 2/8, 2022 at 16:57 Comment(0)
J
0

I have faced the same issue but for me this works as mentioned above but just to clarify how to do it using yarn I have followed below steps

First I have faced below error as mentioned below

Step - 1: Delete the node modules and yarn.lock file first install the node modules using yarn.

Step - 2: Then run yarn prepare which installs the husky package

enter image description here

Step - 3: Now I can run git commit without the above error as shown below.

enter image description here

Jeffreys answered 2/12, 2023 at 16:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.