-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
git commit hooks never get created when husky v5 is installed #866
Comments
Hi @DouglasDev, It's normal behaviour with v5. You need to run You can check that it's working by creating a new folder and running the following commands: $ cd /tmp
$ mkdir test && cd test
$ git init && npm init -y && npm install husky -D
$ npx husky install
$ npx husky add .husky/pre-commit "echo hello"
$ git add package.json
$ git commit -m "test: hello should be printed" |
@typicode the command you provide does not work version husky ^5.0.9 |
@typicode Thanks for your reply. I will take your word for it that it works, but that seems like this change in the installation process will confuse many developers since none the dozens of tutorials on the internet on how to add husky to a project (for example the create react app docs and the prettier docs) mention this. I guess this change is necessary for the improved performance/memory usage? Perhaps it would be helpful to show these instructions in the terminal after you install husky? |
husky@4.2.3 works |
I have the same issue! They worked well with my husky.config.js
|
Could be related to #869. Try the fix provided in this issue. |
I have the same issue since i upgraded to 5.0.9, i am using lint-staged 10.5.4 |
In windows environments the same problem exists (see #871). In that case it can be solved by calling the locally installed version of husky ( |
@typicode I think shome people are likely just missing that Husky 5 doesn't read the config found in package.json anymore, and that's muddying the waters on these threads (as per comment & comment) For anyone using husky 5, to setup lint-staged with husky 5, just run: npx husky add .husky/pre-commit "yarn run lint-staged"
# or
npx husky add .husky/pre-commit "npx lint-staged" And drop the |
for me the problem was npx. I am on a windows 10 machine with node LTS (V14 with npm v6). That the husky configuration change with V5 is clearly described in the documentation (and has a longer discussion in an issue :-) |
I have the same issue with node v12.20.1, yarn v1.22.10, macOS v11.2. |
Apparently it's a bug with npx on Windows, it seems to be fixed in npm v7.5.4 |
Same issue here, we're still using npm@6 on Windows 10 and the command "scripts": {
"commitlint": "commitlint",
"lint-staged": "lint-staged",
} And thanks to that, my 2 files (with shebang as proposed here: #864 (comment)) are now triggered when I do ".husky/commit-msg": #!/usr/bin/env bash
npm run commitlint -- --edit $1 ".husky/pre-commit": #!/usr/bin/env bash
npm run lint-staged If it can help someone 😊 Thanks for this upgrade @typicode ! |
@typicode Can you point me to the bug in npx? |
https://typicode.github.io/husky/#/?id=migrate-from-v4-to-v5 Additional changes: - Use prepare script instead of postinstall: typicode/husky#890 - Remove old package.json > husky field - Add `lint-staged` to package scripts & prefix `pre-commit` with npx typicode/husky#866 (comment) Signed-off-by: Roger Sheen <roger@infotexture.net>
@jordanbtucker don't have a link sorry. However a temporary fix was provided here before the official one #873 (I did some tests too, and I think it's fixed in npm v7.4). |
Recently, a new command has been introduced to simplify setup. You can now just run:
I hope it makes things more straightforward :) Docs have been updated. Also if you're using npm, pnpm or yarn v1, you can just have |
https://typicode.github.io/husky/#/?id=migrate-from-v4-to-v5 Additional changes: - Use prepare script instead of postinstall: typicode/husky#890 - Remove old package.json > husky field - Add `lint-staged` to package scripts & prefix `pre-commit` with npx typicode/husky#866 (comment) Signed-off-by: Roger Sheen <roger@infotexture.net>
I added backslash as a workaround. but it doesn't work if it is put in package.json |
Installing husky 5 with
npm i husky
doesn't create the commit hooks when used with git version 2.20.1, node v14.15.4, and npm v6.14.10 on mac in a new project. I confirmed this by opening the .git folder for my project and checking the hooks folder, and it was unchanged after installation. I think I was having the same issue as several other people in this issue: #326I spent hours trying all the methods listed in that issue and the only one that worked was installing husky@4.2.3 which fixed the problem immediately, leading me to believe that there was a bug introduced in version 5. Please let me know if you need any other details.
The text was updated successfully, but these errors were encountered: