husky: Command "husky-run" not found.

Just have upgraded from v4.3.8 to v5.0.9 and got the error

have tried to uninstall/install husky, remove npde_modules - nothing helped

> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
error Command "husky-run" not found.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 98
  • Comments: 66 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Try yarn husky install

Try, npx husky install.

Alright, figured out how to fix it.

Firstly, we need to remove .git/hooks.

For me, I ran typicodes husky-4-to-5, which worked like a charm.

Then, run yarn / npx husky install.

Viola, should work. You can check out my repo to check out how I did it.

Some additional resources: From my testing, you can not add a .sh or any file extension to the end of a hook file. Add a hook using yarn husky add '.husky/hook-name' 'optional content here' (or npx) How you can run commitlint:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

echo '$ commit-msg' 
echo '$ yarn commitlint -e $1'
yarn commitlint -e $1

Have a great day. 👋

Leave me a comment if this helped you out!

Initially, followed @Milo123459 and deleted .git/hooks and then was getting an error in following the next steps and git was committing code without hooks. Then tried yarn husky install and yarn husky add .husky/pre-commit "lint-staged" it worked. btw node is v15.8.0

Replace lint-staged with yarn lint-staged

To fix husky-run not found, install husky 5 and run husky init script:

With yarn:

yarn add husky -D && yarn husky init

With pnpm:

pnpm add husky -D && pnpx husky install

It will set up hooks and create a pre-commit hook that you can edit in .husky/pre-commit. If you want to add another hook, it’s highly recommended to use husky add ... command.

Optionally, you can delete .git/hooks to remove artifacts from husky 4 (it’s automatically done if you upgrade with npm).

There’s also section for migrating from husky 4 to 5 in the docs: https://typicode.github.io/husky/#/

Hope this helps 😃

do on Mac

yarn add husky
yarn husky install
yarn husky add .husky/pre-commit "yarn lint-staged"
. . . 
yarn husky add .husky/hookN "..."

it works!

package.json add "prepare": "npx husky install",

Initially, followed @Milo123459 and deleted .git/hooks and then was getting an error in following the next steps and git was committing code without hooks. Then tried yarn husky install and yarn husky add .husky/pre-commit "lint-staged" it worked. btw node is v15.8.0

Glad it worked!

@SalahAdDin Can you post that issue here and your fix?

Issue and fix: https://github.com/typicode/husky/issues/875

but my previous hooks are lost!!! 😦 my commitizen hooks are out of husky flow

That looks like husky6, this issue covered husky 5…

No way, Husky 6?

I found this very helpful for mac osX - https://dev.to/studiospindle/using-husky-s-pre-commit-hook-with-a-gui-21ch Creating a huskyrc in the home directory and adding the path to your local/user npm files (PATH="/usr/local/bin:/Users/julian/.npm/bin:$PATH") fixed the problems I had with husky not being able to find yarn despite having the npm/bin path in my global PATH

No. I’m on my phone, just replace $HUSKY_GIT_PARAMS with $1

Alright, figured out how to fix it.

Firstly, we need to remove .git/hooks.

For me, I ran typicodes husky-4-to-5, which worked like a charm.

Then, run yarn / npx husky install.

Viola, should work. You can check out my repo to check out how I did it.

Have a great day. 👋

Leave me a comment if this helped you out!

it did not help me 😦 after reinstalling husky - it does not create /hooks folder in .git

@SalahAdDin try yarn lint-staged as seen in my example.

We’re on the same page there, saying the same thing in different ways 👍

Package.json scripts are isolated which gives access to all binaries installed. The SH file is not. That’s why you have to prefix it.

I suggest just using yarn. That comment was purely for the fact he was using yarn, but you could do npx rather then yarn.

Initially, followed @Milo123459 and deleted .git/hooks and then was getting an error in following the next steps and git was committing code without hooks. Then tried yarn husky install and yarn husky add .husky/pre-commit "lint-staged" it worked. btw node is v15.8.0

Should you use yarn lint-staged in your pre-commit as @Milo123459 suggests in the comment here?

I’m doing the same and neither command errors on commit, but when run manually, only the command run as a yarn argument works.

Thanks, @Milo123459 your suggestion works like a charm 🙌

Can confirm. This is so ridiculously annoying. Here is my solution