Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cjoecker opened this issue Apr 19, 2020 · 21 comments
Closed

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

cjoecker opened this issue Apr 19, 2020 · 21 comments
Labels

Comments

@cjoecker
Copy link

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
Copy link

zuzusik commented Apr 22, 2020

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

@Thorbenl
Copy link

Thorbenl commented Apr 23, 2020

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
Copy link

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
Copy link

akullpp commented May 11, 2020

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
Copy link

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

@dan-hut
Copy link

dan-hut commented May 14, 2020

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
Copy link

RichH73 commented Aug 3, 2020

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
Copy link

tibic commented Aug 27, 2020

image

what's wrong?

@Shinobi247
Copy link

Shinobi247 commented Sep 4, 2020

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
Copy link

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

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

@AsifArko
Copy link

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

@AnandB23
Copy link

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
Copy link

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
Copy link

rpilev commented Dec 2, 2020

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
Copy link

rpilev commented Feb 8, 2021

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
Copy link

Lutic commented Feb 11, 2021

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

@iegik
Copy link

iegik commented Mar 20, 2021

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
Copy link

gremmil commented Mar 23, 2021

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
Copy link

alx8437 commented Apr 28, 2021

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

@stale
Copy link

stale bot commented Jul 2, 2021

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.

@stale stale bot added the wontfix label Jul 2, 2021
@stale stale bot closed this as completed Jul 9, 2021
@mujeebalam701
Copy link

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

Repository owner locked and limited conversation to collaborators Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests