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

Command "husky-run" not found. #854

Closed
budarin opened this issue Feb 9, 2021 · 66 comments
Closed

Command "husky-run" not found. #854

budarin opened this issue Feb 9, 2021 · 66 comments

Comments

@budarin
Copy link

budarin commented Feb 9, 2021

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.
@Milo123459
Copy link

Milo123459 commented Feb 9, 2021

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

@typicode
Copy link
Owner

typicode commented Feb 9, 2021

Hi @budarin,

Could you provide steps to reproduce the issue? Also are you using Git 2.9+?

@budarin
Copy link
Author

budarin commented Feb 9, 2021

git version 2.30.0 (2.30.0.windows.2)

steps to reproduce - upgrade husky to the latest ver.
on both platforms: Windows and MacOS

@Milo123459
Copy link

Git version: 2.30.0.windows.2, if this is required for git 2.9+ then there needs to be support for older versions

@typicode
Copy link
Owner

typicode commented Feb 9, 2021

Hmm, can't try right now on Windows. But here are the steps I've done and it seems to work. Let me know if I'm missing something.

/tmp/foo main
❯ git init
Initialized empty Git repository in /tmp/foo/.git/

/tmp/foo main*
❯ npm init -y
Wrote to /tmp/foo/package.json:

{
  "name": "foo",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "husky": "^4.3.8"
  },
  "dependencies": {},
  "description": ""
}



/tmp/foo main*
❯ npm install husky@4 -D

> husky@4.3.8 preuninstall /tmp/foo/node_modules/husky
> node husky uninstall

husky > Uninstalling git hooks
husky > Done

> husky@4.3.8 install /tmp/foo/node_modules/husky
> node husky install

husky > Setting up git hooks
husky > Done

> husky@4.3.8 postinstall /tmp/foo/node_modules/husky
> opencollective-postinstall || exit 0

Thank you for using husky!
If you rely on this package, please consider supporting our open collective:
> https://opencollective.com/husky/donate

npm WARN foo@1.0.0 No description
npm WARN foo@1.0.0 No repository field.

+ husky@4.3.8
updated 1 package and audited 47 packages in 1.883s

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities


/tmp/foo main*
❯ npm install husky@5 -D

> husky@4.3.8 preuninstall /tmp/foo/node_modules/husky
> node husky uninstall

husky > Uninstalling git hooks
husky > Done
npm WARN foo@1.0.0 No description
npm WARN foo@1.0.0 No repository field.

+ husky@5.0.9
removed 46 packages, updated 1 package and audited 1 package in 0.67s

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities


/tmp/foo main*
❯ npx husky install
husky - Git hooks installed

/tmp/foo main*
❯ npx husky add .husky/pre-commit "echo hello && exit 1"
created .husky/pre-commit

/tmp/foo main*
❯ git add package.json

/tmp/foo main*
❯ git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
hello
husky - pre-commit hook exited with code 1 (error)

@Milo123459
Copy link

^ After downgrading and building again, it just, doesn't work. I've got an idea but a faint one.

@Milo123459
Copy link

Milo123459 commented Feb 9, 2021

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!

@mo-sharif
Copy link

Thanks, @Milo123459 your suggestion works like a charm 🙌

@Milo123459
Copy link

Glad it does 😉

@budarin
Copy link
Author

budarin commented Feb 9, 2021

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

@Milo123459
Copy link

Milo123459 commented Feb 9, 2021

What's happened meaning it didn't work?
Can you send me if it errors?

@budarin
Copy link
Author

budarin commented Feb 9, 2021

What's happened meaning it didn't work?
Can you send me if it errors?

there were no errors - hooks folder had not been created with husky

@Milo123459
Copy link

Try, npx husky install.

@budarin
Copy link
Author

budarin commented Feb 9, 2021

Try, npx husky install.

image

image

You could see that husky does not recreate hooks folder during installation

@Milo123459
Copy link

Try yarn husky install

@budarin budarin closed this as completed Feb 9, 2021
@budarin
Copy link
Author

budarin commented Feb 9, 2021

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

@budarin budarin reopened this Feb 9, 2021
@Milo123459
Copy link

Firstly, don't close this issue, it'll be helpful for other users.
Secondly, they should still be in your package.json

@Milo123459
Copy link

Did you run husky 4 to 5?

@budarin
Copy link
Author

budarin commented Feb 9, 2021

Firstly, don't close this issue, it'll be helpful for other users.
Secondly, they should still be in your package.json

they are in package.json but not used with husky in commit process

@Milo123459
Copy link

yarn husky add .husky/hook-name "script to run"

@budarin
Copy link
Author

budarin commented Feb 9, 2021

Did you run husky 4 to 5?

23 verbose stack Error: could not determine executable to run
23 verbose stack     at getBinFromManifest (C:\Program Files\nodejs\node_modules\npm\lib\exec.js:264:23)
23 verbose stack     at exec (C:\Program Files\nodejs\node_modules\npm\lib\exec.js:178:15)
24 verbose cwd C:\Usersастер\AppData\Local\npm-cache\_cacache\tmp\git-clone-bc12e66d

@budarin
Copy link
Author

budarin commented Feb 9, 2021

yarn husky add .husky/hook-name "script to run"

I used to use huskyrc.js - now it's useless?

@Milo123459
Copy link

Yes.

@Milo123459
Copy link

Did you run husky 4 to 5?

23 verbose stack Error: could not determine executable to run

23 verbose stack     at getBinFromManifest (C:\Program Files\nodejs\node_modules\npm\lib\exec.js:264:23)

23 verbose stack     at exec (C:\Program Files\nodejs\node_modules\npm\lib\exec.js:178:15)

24 verbose cwd C:\Usersастер\AppData\Local\npm-cache\_cacache\tmp\git-clone-bc12e66d

I node version?

@budarin
Copy link
Author

budarin commented Feb 9, 2021

Did you run husky 4 to 5?

23 verbose stack Error: could not determine executable to run

23 verbose stack     at getBinFromManifest (C:\Program Files\nodejs\node_modules\npm\lib\exec.js:264:23)

23 verbose stack     at exec (C:\Program Files\nodejs\node_modules\npm\lib\exec.js:178:15)

24 verbose cwd C:\Usersастер\AppData\Local\npm-cache\_cacache\tmp\git-clone-bc12e66d

I node version?

v15.8.0

@Milo123459
Copy link

Never mind on that, just convert everything to .husky/hook

@budarin
Copy link
Author

budarin commented Feb 9, 2021

do
yarn husky add .husky/pre-commit "lint-staged"

then try to commit - got the error:

> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
.husky/pre-commit: line 4: lint-staged: command not found
husky - pre-commit hook exited with code 127 (error)

@Milo123459
Copy link

Replace lint-staged with yarn lint-staged

@inhaq
Copy link

inhaq commented Feb 10, 2021

@PaulMEdwards yup, using yarn but you can use npx as well mentioned above by @Milo123459

@Milo123459
Copy link

There probably is a way to isolate the sh files like package.json scripts, but it'll have to work for pnpm and yarn v2 which is a pain.

@shellscape
Copy link

shellscape commented Feb 19, 2021

Can confirm that the latest version of 5.x is broken again with pnpm. Looking at issues between pnpm and husky repos, this seems to pop up as an issue at least once a year. Can't help but wonder if something can be done to prevent these regressions. Also confirming that v4.3.8 does still work with pnpm.

@Milo123459
Copy link

pnpx. Use pnpx.

@shellscape
Copy link

@Milo123459 that's a workaround, not a solution. I'd expect husky to behave the same on install between 4.x and 5.x. As it is, it's broken.

@Milo123459
Copy link

It's not pnpms fault. It's husky's. The script just has to be isolated like the npm scripts are. I'm sure there is a way to do that.

Also, at least it works, better then nothing! 😅

@shellscape
Copy link

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

hasparus added a commit to hasparus/theme-ui that referenced this issue Feb 25, 2021
@SalahAdDin
Copy link

SalahAdDin commented Feb 28, 2021

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

Well, this does not work for me, hooks are not working now.

@Milo123459 that's a workaround, not a solution. I'd expect husky to behave the same on install between 4.x and 5.x. As it is, it's broken.

Indeed it is.

@Milo123459
Copy link

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

@SalahAdDin
Copy link

I solved it by the GitKraken related issue.

@kevinschaffter
Copy link

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

@typicode
Copy link
Owner

typicode commented Mar 4, 2021

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 :)

@typicode typicode closed this as completed Mar 4, 2021
@SalahAdDin
Copy link

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

Issue and fix: #875

garyli2 added a commit to garyli2/Nightstand that referenced this issue Mar 9, 2021
Electron v12 introduced a breaking change, so we need to set contextIsolation to false for our app to continue to work.
Also update husky to fix husky-run command not found, as seen in typicode/husky/issues/854, and lint-staged not found, in typicode/husky/issues/618 and prettier config change https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md#version-800-2021-02-21
@shellscape
Copy link

@typicode running yarn husky init results in the following:

Usage
  husky install [dir] (default: .husky)
  husky uninstall
  husky set|add <file> [cmd]

You closed this issue with bad info.

@Milo123459
Copy link

That looks like husky6, this issue covered husky 5..

@SalahAdDin
Copy link

That looks like husky6, this issue covered husky 5..

No way, Husky 6?

@guaizi149
Copy link

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

@sourceful-julian
Copy link

sourceful-julian commented Jul 6, 2021

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

@asvetlenko
Copy link

I have the same issue:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests