husky: pre-commit hook failed (add --no-verify to bypass)
I’m getting the following error:
Commit failed with error
0 file committed, 2 files failed to commit: Add reformat with prettier and eslint precommit
husky > pre-commit (node v13.9.0)
C:\Users\...\frontend\node_modules\.bin/../node/bin/node: line 1: This: command not found
husky > pre-commit hook failed (add --no-verify to bypass)
This is my package.json
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"prettier --write",
"eslint --fix",
"git add"
],
"*.{html,css,less,ejs,json}": [
"prettier --write",
"git add"
]
}
I tried everything that is mentioned here but nothing works.
I have the latest vesion of everything: intellij IDEA 2020.1, node 13.13.0, npm 6,14,4, git 2.24.0.windows.2, husky 4.2.5
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 12
- Comments: 21
Finally found a solution. The issue (even though it’s not an issue! ) is because of the hooks created by react. I simply deleted the hooks folder for git which defines the pre-commit hooks and hence can push after that.
Edit: You can also skip hooks when you provide the git command line argument —no-verify, git push origin master --no-verify, or use Sourcetree‘s Bypass commit hooks setting (in the menu to the top right of the commit message field)
Hey @cjoecker, I believe this issue is because of the fact that
git
has its ownpre-hooks
, and now, with husky, you have added yours. I think there is a conflict between those two.For a temporary solution, you can just delete the
hook
folder from./git
folder from your project or maybe move it out of your project folder(if you want). This worked for me. Hope so for you too.I updated husky to the latest version (^5.0.9) and the problem was gone.
same here, with husky 4.2.5,eslint 7.0.0, prettier 2.0.5,pre-commit doesn’t work.
Running
husky-run lint-staged
we can face an errorlint-staged: command not found ... code 1
:…from following line:
node_modules/husky/lib/runner/index.js:48
So, this means, that
lint-staged
command is not found innode_modules/.bin/lint-staged -> ../lint-staged/bin/lint-staged.js
You just forgot to install it! (But it works running
npx lint-staged
)The REAL solution is:
Not really a solution if you want the hooks to run. If you just delete the folder then it just stops working. I am having the same issue. Only happens on my Windows machine and I still haven’t found a solution.
When I try to make a commit I get this:
...>git commit -m "test"
package.json
.huskyrc.json
.lintstagedrc.json
On Mac and Linux this issue does not seem to happen. I tired uninstalling nodejs and installing the latest version, but it did not help.
Edit:
Managed to make it work by changing
.huskyrc.json to
However now I am just bypassing lint-staged, but what if I want that to work too?
Same on Windows:
Why is it using node v11, when I have another node version installed?