typicode / husky

Git hooks made easy šŸ¶ woof!
https://typicode.github.io/husky
MIT License
31.82k stars 1k forks source link

pre-commit hook failed (add --no-verify to bypass) #716

Closed cjoecker closed 2 years ago

cjoecker commented 4 years ago

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

zuzusik commented 4 years ago

@typicode it seems like reverting back to using run-node might be a good idea...

Thorbenl commented 4 years ago

Have a similiar problem, with additionall data:

husky > pre-commit (node v13.8.0)
lint-staged requires at least version 10.13.0 of Node, please upgrade
husky > pre-commit hook failed (add --no-verify to bypass)

no, not using nvm :) every dev is on the latest node anyway

BlakePetersen commented 4 years ago

Same situation as @Thorbenl cept mine is barking about prettier and we are not using husky in this repo. Probably not be specific to husky ultimately.

prettier requires at least version 10.13.0 of Node, please upgrade

akullpp commented 4 years ago

Same on Windows:

husky > pre-commit (node v11.15.0)
<CENSORED>\node_modules\.bin/../node/bin/node: line 1: This: command not found

Why is it using node v11, when I have another node version installed?

node --version
v12.16.3
smancang commented 4 years ago

same here, with husky 4.2.5,eslint 7.0.0, prettier 2.0.5ļ¼Œpre-commit doesn't work.

dan-hut commented 4 years ago

I had the same problem on babun console with

git version 2.21.0 node v12.13.0, "husky": "^4.2.5", "lint-staged": "^10.2.2"

Downgrading "lint-staged" to version 8.1.7 fixed the issue.

RichH73 commented 3 years ago

I ran into the same issue. I copied "husky": "^4.2.5" from devDependencies and added to dependencies. Ran npm i again and all was well.

tibic commented 3 years ago

image

what's wrong?

Shinobi247 commented 3 years ago

Hey @cjoecker, I believe this issue is because of the fact that git has its own pre-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.

vijayakumarbathini commented 3 years ago

Facing same issue for pre-commit hook failed with below husky

"husky": { "hooks": { "pre-commit": "lint-staged && npm run precommit" } },

AsifArko commented 3 years ago

Not compitable with node 10. tried with node 12.18.3 .worked great

AnandB23 commented 3 years ago

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)

FrancisChung commented 3 years ago

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.

This worked for me. Thanks @AnandB23, you saved me from wasting more hours on this

rpilev commented 3 years ago

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)

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"

husky > pre-commit (node v14.15.1)
C:\Program Files\nodejs/node_modules/node/bin/node: line 1: This: command not found
husky > pre-commit hook failed (add --no-verify to bypass)

package.json

  "devDependencies": {
    ...
    "husky": "^4.3.0",
    "lint-staged": "^10.5.1",
    ...
  }

.huskyrc.json

{
  "hooks": {
    "pre-commit": "lint-staged"
  }
}

.lintstagedrc.json

{
  "*.+(js|jsx)": ["eslint"]
}

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

{
  "hooks": {
    "pre-commit": "npm run lint"
  }
}

However now I am just bypassing lint-staged, but what if I want that to work too?

rpilev commented 3 years ago

Is there any update to this? I am still having the same problem. I cannot use lint-staged and husky together on my Windows 10 machine. What could be causing this? What can I do?

...>git commit -m "test"
husky > pre-commit (node v14.15.1)
C:\Program Files\nodejs/node_modules/node/bin/node: line 1: This: command not found
husky > pre-commit hook failed (add --no-verify to bypass)
Lutic commented 3 years ago

I updated husky to the latest version (^5.0.9) and the problem was gone.

iegik commented 3 years ago

Running husky-run lint-staged we can face an error lint-staged: command not found ... code 1:

husky > pre-commit (node v14.5.0)
sh: lint-staged: command not found
husky > pre-commit hook failed (add --no-verify to bypass)
npm ERR! code 1
npm ERR! path ~/Development/project
npm ERR! command failed
npm ERR! command sh -c husky-run "pre-commit" ""

npm ERR! A complete log of this run can be found in:
npm ERR!     ~/.npm/_logs/2021-03-20T10_11_56_707Z-debug.log

...from following line:

node_modules/husky/lib/runner/index.js:48

    if (status !== 0) {
        const noVerifyMessage = [
            'commit-msg',
            'pre-commit', /* <-- we are here */
            'pre-rebase',
            'pre-push',
        ].includes(hookName)
            ? '(add --no-verify to bypass)' /* <-- we are here */
            : '(cannot be bypassed with --no-verify due to Git specs)';
        console.log(`husky > ${hookName} hook failed ${noVerifyMessage}`);
    }
    // If shell exits with 127 it means that some command was not found.
    // However, if husky has been deleted from node_modules, it'll be a 127 too.
    // To be able to distinguish between both cases, 127 is changed to 1.
    if (status === 127) {
        return 1;
    }

So, this means, that lint-staged command is not found in node_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:

npm install --save-dev lint-staged
gremmil commented 3 years ago

I updated husky to the latest version (^5.0.9) and the problem was gone.

Before trying to upgrade to a higher version, note that in higher versions git hooks are not installed automatically so you have to create an additional configuration file for your hooks. If your project relies heavily on automating git tasks consider first reviewing the general changes at: https://dev.to/typicode/what-s-new-in-husky-5-32g5

And the migration process from version 4 to 5 in: https://typicode.github.io/husky/#/?id=migrate-from-v4-to-v5

I hope that it will be useful to you and forgive my English, I do not master it well, Greetings!

alx8437 commented 3 years ago

Hello. I have this error when my JEST tests isn't solved

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

mujeebalam701 commented 3 months ago

check your node version compatibility with npm, its work in my side.