husky: git hook install triggered via npm but not yarn

Do you want to request a feature or report a bug? => Bug

Installing the git hook is only triggered when husky is installed via npm but not yarn whereas uninstalling the hooks works for both tools. Similar to #81

Current Behaviour

Install

$ yarn add husky@0.15.0-rc.3 -D
arn add v1.4.0
[1/4] ๐Ÿ”  Resolving packages...
[2/4] ๐Ÿšš  Fetching packages...
[3/4] ๐Ÿ”—  Linking dependencies...
[4/4] ๐Ÿ“ƒ  Building fresh packages...
success Saved lockfile.
success Saved 5 new dependencies.
โ”œโ”€ ci-info@1.1.2
โ”œโ”€ husky@0.14.3
โ”œโ”€ is-ci@1.1.0
โ”œโ”€ normalize-path@1.0.0
โ””โ”€ strip-indent@2.0.0
โœจ  Done in 3.13s.

and npm

$ npm i husky@0.15.0-rc.3 --save-dev
...
> husky@0.15.0-rc.3 postinstall /Users/abc/Development/project/node_modules/husky
> node lib/installer/bin install

husky > setting up git hooks
husky > done
+ husky@0.15.0-rc.3
added 8 packages, removed 575 packages and updated 47 packages in 8.268s

Uninstall

$ yarn remove husky
yarn remove v1.4.0
[1/2] Removing module husky...
$ node ./bin/uninstall.js
husky
uninstalling Git hooks
done

$ node ./bin/uninstall.js
husky
uninstalling Git hooks
done

[2/2] Regenerating lockfile and installing missing dependencies...
success Uninstalled packages.
โœจ  Done in 2.83s.

and npm

$ npm un husky --save-dev
> husky@0.15.0-rc.3 preuninstall /Users/abc/Development/project/node_modules/husky
> node lib/installer/bin uninstall

husky > uninstalling git hooks
husky > done
added 483 packages, removed 14 packages and updated 22 packages in 18.134s

Expected Behaviour

yarn add husky@0.15.0-rc.3 -D should also trigger the install of the git hooks.

Please mention your node.js, yarn and operating system version.

OS: macOS High Sierra 10.13.3 yarn: v1.4.0 node: v9.4.0 npm: 5.6.0

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 14
  • Comments: 20 (4 by maintainers)

Most upvoted comments

Iโ€™m experiencing this with husky v3.0.1 Had to use https://github.com/typicode/husky/issues/227#issuecomment-361779926

@mavogel thanks for the detailed issue ๐Ÿ‘ thatโ€™s super helpful ๐Ÿ˜ƒ Iโ€™m not getting this issue with yarn v1.3.2, so not sure if itโ€™s related to husky install script. Iโ€™ll have to try with yarn v1.4.0.

@fernandopasik https://github.com/typicode/husky/pull/126 could have but not really ๐Ÿ˜ƒ The PR is only for picking between npm or yarn when running a package.json script (for example, it would run precommit with yarn precommit or npm run precommit depending on which one is installed) and wouldnโ€™t have any effect during husky installation.

Meanwhile, as a temporary workaround, you can manually run node node_modules/husky/lib/installer/bin install or add it to your package.json:

{
  "scripts": {
    "postinstall": "node node_modules/husky/lib/installer/bin install"
  }
}

One word of caution, use the postinstall hook only if youโ€™re not publishing your project on npm, else your users will get errors when trying to install your module.

Same here ! Could we please re-open this issue ?

husky: 3.1.0 node: 12.10.0 (via nvm) yarn: 1.19.2 npm: 6.13.0

It does not install hooks on yarn add but npm install does

@typicode FWIW Iโ€™m using v1.3.2:

โฏ yarn add husky
yarn add v1.3.2
[1/4] ๐Ÿ”  Resolving packages...
[2/4] ๐Ÿšš  Fetching packages...
[3/4] ๐Ÿ”—  Linking dependencies...
[4/4] ๐Ÿ“ƒ  Building fresh packages...
success Saved lockfile.
success Saved 2 new dependencies.
โ”œโ”€ husky@0.14.3
โ””โ”€ strip-indent@2.0.0
โœจ  Done in 3.00s.

โฏ yarn -v
1.3.2

I had the same problem and I fixed it upgrading git.

Installing Husky didnโ€™t create the hooks.

I tried running the script directly:

node node_modules/husky/lib/installer/bin install

And got this:

husky > Setting up git hooks
Husky requires Git >=2.13.0. Got v2.10.2.
husky > Failed to install

I guessed that during the installation this error was hidden among all the logs and I didnโ€™t see it.

After updating git, I removed node_modules and run yarn install again. Everything worked.

I hope this helps ๐Ÿ˜„

experiencing this with husky: 3.0.9 node: 12.2.0 (via nvm) yarn: 1.19.1 yarn workspaces

yarn install husky --dev -W

โ˜๏ธ does not create the git hooks, confirmed via ls -l .git/hooks

Manually running huskyโ€™s bin install script does work though https://github.com/typicode/husky/issues/227#issuecomment-361779926

Iโ€™ve published a new version if you want to give another try (just run yarn add husky@next --dev). Iโ€™ve moved v0.15 install script from postinstall to install (as it is in v0.14).