husky: Does not install git hooks when using yarn

When running yarn add husky --dev, the git hooks do not get set up. I have to run the install script manually, and then it works fine.

Yarn version: 0.17.9

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 18
  • Comments: 40 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Why is this closed? The actual issue is not solved, is still happening in:

yarn 1.22.0
node v13.7.0
husky ^4.2.3

When I try to run the above command, it fails:

node ./node_modules/husky/lib/installer/bin install
husky > Setting up git hooks
Cannot destructure property 'name' of 'which_pm_runs_1.default(...)' as it is undefined.
husky > Failed to install

Removing .git/hooks didn’t work either, neither adding it as a postinstall script did

@typicode Encountering this again.

Yarn 1.9.4 npm 6.4.1 node v8.11.4 husky1.0.0-rc.14

To get around this and force it, I added to my package.json’s scripts:

  "postinstall": "node ./node_modules/husky/lib/installer/bin install"

I’m still having this issue:

yarn 1.22.5
node v14.12.0
husky ^5.0.9

after running yarn add --dev husky --force and cat .git/hooks/pre-commit I’ve still got cat: .git/hooks/pre-commit: No such file or directory

I’ve also tried running install.js directly from the command line via node ./node_modules/husky/lib/commands/install but that didn’t work either. That’s how the husky package is now structured; the above command errored for me.

The hooks won’t get created for me either.

node 14.15.4
yarn 1.22.10
husky 5.0.9

The hooks won’t run, install says it’s successful but it doesn’t create any hooks.

node_modules/.bin/husky install     
husky - Git hooks installed

But when I commit, it immediately proceeds without running anything.

package.json:

  "husky": {
    "hooks": {
      "pre-commit": "echo 'RUNNING HOOK!'"
    }
  }

I’ve spent a lot of time trying to figure out what is wrong, but the things are that they have changed the entire approach.

For those who are still struggling with this issue, and for newcomers: read Husky 5 Release announcement especially sections “Optional install” and “Config”:

With husky 4, hooks were automatically installed. With husky 5, you have the choice and it’s explicit.

Moreover, from the “Config” section:

Previously, hooks were defined in package.json or .huskyrc. Now they’re defined directly in their corresponding hook file. Overhead is reduced and scripting is easier.

dammit…

99.9999% of existing materials described husky integration become trash…

Getting the same issue as @Nikodermus here’s my setup:

yarn 1.22.4
node 12.16.0
husky ^4.2.3

Same problem here using 1.13.0 and latest version of husky

Hi @avaly,

Yes it will. I have a few ideas for this but need to do some testing.

Hi,

husky 5 has a breaking change regarding config, .huskyrc isn’t supported anymore. See docs for install or migration steps.

Why is this closed? The actual issue is not solved, is still happening in:

yarn 1.22.0
node v13.7.0
husky ^4.2.3

When I try to run the above command, it fails:

node ./node_modules/husky/lib/installer/bin install
husky > Setting up git hooks
Cannot destructure property 'name' of 'which_pm_runs_1.default(...)' as it is undefined.
husky > Failed to install

Removing .git/hooks didn’t work either, neither adding it as a postinstall script did

using the version ‘3.1.0’ solved my problem.

    "husky": "^3.1.0",

Just faced the same problem with yarn v0.24.5, same with fresh yarn cache (i.e. afteryarn cache clean). Only yarn add --dev husky --force helps.

Can be reproduced on my booted.

Turns out husky v5 does not pull hooks from package.json anymore. You have to use husky add [hook-name] [command]

In my opinion, that’s worse as it pollutes the tree with another set of plain script files, which contain the command itself, instead of abstracting the command into the runner… Also husky add doesn’t always chmod the file properly, so it’s more steps to make hooks work, plus they’re uglier now.

@cat-walk you are experiencing that issue because you are not running that command through yarn so the script cannot infer your package manager name, the error is not very explicative in this case. Try adding:

    "setuphusky": "node ./node_modules/husky/husky.js install"

to your package json and then run:

yarn run setuphusky

Why is this closed? The actual issue is not solved, is still happening in:

yarn 1.22.0
node v13.7.0
husky ^4.2.3

When I try to run the above command, it fails:

node ./node_modules/husky/lib/installer/bin install
husky > Setting up git hooks
Cannot destructure property 'name' of 'which_pm_runs_1.default(...)' as it is undefined.
husky > Failed to install

Removing .git/hooks didn’t work either, neither adding it as a postinstall script did

@Nikodermus Have you solved this problem?

So google can find it for the next guy:

husky hooks not working manually install

Execute this in your command line:

node ./node_modules/husky/lib/installer/bin install

The hooks won’t get created for me either.

node 14.15.4
yarn 1.22.10
husky 5.0.9

The hooks won’t run, install says it’s successful but it doesn’t create any hooks.

node_modules/.bin/husky install     
husky - Git hooks installed

But when I commit, it immediately proceeds without running anything.

package.json:

  "husky": {
    "hooks": {
      "pre-commit": "echo 'RUNNING HOOK!'"
    }
  }

Same for us on https://github.com/decathlon/vitamin-web

For me it was git version. I’ve updated git version and it worked like charm. Make sure your git is > 2.13

I’ve encountered a few issues with it too 😦. Had to remove the hook manually from .git/hooks/ then yarn add husky --dev --force to make it work.