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

Husky hooks skipped #639

Closed
Alex0007 opened this issue Jan 10, 2020 · 47 comments
Closed

Husky hooks skipped #639

Alex0007 opened this issue Jan 10, 2020 · 47 comments

Comments

@Alex0007
Copy link

Alex0007 commented Jan 10, 2020

OS: MacOS 10.15.2 (19C57)
Git: git version 2.24.1

❯ which git
/usr/local/bin/git

❯ node -v
v13.5.0

❯ which node
/usr/local/bin/node

❯ which npx
/usr/local/bin/npx

Node.js installed with brew package manager

    "husky": "^4.0.6",

When making commit in VSCode GUI

Can't find npx in PATH: /usr/local/Cellar/git/2.24.1/libexec/git-core:/usr/bin:/bin:/usr/sbin:/sbin
Skipping pre-commit hook
Can't find npx in PATH: /usr/local/Cellar/git/2.24.1/libexec/git-core:/usr/bin:/bin:/usr/sbin:/sbin
Skipping prepare-commit-msg hook
Can't find npx in PATH: /usr/local/Cellar/git/2.24.1/libexec/git-core:/usr/bin:/bin:/usr/sbin:/sbin
Skipping commit-msg hook
Can't find npx in PATH: /usr/local/Cellar/git/2.24.1/libexec/git-core:/usr/bin:/bin:/usr/sbin:/sbin
Skipping post-commit hook

Everything works fine when making commit from VSCode terminal.


Version 3 works fine. Sample output from v3:

Info: can't find node in PATH, trying to find a node binary on your system
husky > pre-commit (node v13.5.0)
Stashing changes... [started]
Stashing changes... [skipped]
→ No partially staged files found...
Running tasks... [started]
Running tasks for *.{js,ts,tsx,css,md} [started]
tslint --fix [started]
tslint --fix [completed]
prettier --write [started]
prettier --write [completed]
git add [started]
git add [completed]
Running tasks for *.{js,ts,tsx,css,md} [completed]
Running tasks... [completed]
@typicode
Copy link
Owner

typicode commented Jan 11, 2020

@Alex0007 thanks for the report. It seems that npx isn't in PATH, can you try https://docs.brew.sh/FAQ#my-mac-apps-dont-find-usrlocalbin-utilities or add this in ~/.huskyrc:

PATH="/usr/local/bin:$PATH"

@Alex0007
Copy link
Author

Alex0007 commented Jan 12, 2020

can you try https://docs.brew.sh/FAQ#my-mac-apps-dont-find-usrlocalbin-utilities

This one worked for me

@sholladay
Copy link

sholladay commented Jan 13, 2020

Something similar is happening to me in Tower as of Husky v4. It is a regression within Husky, as it works correctly with Husky v3.

This was caused by the removal of run-node in PR #625.

husky v4 skips hooks in Tower

@typicode
Copy link
Owner

@sholladay how was Node installed? If it was with homebrew, have you tried the suggested command?

Also are you using Husky 4.0.9?

@sholladay
Copy link

sholladay commented Jan 15, 2020

@typicode yes, I have Node installed via Homebrew. I think I'd rather leave the PATH for GUI apps at its default and just stay on Husky v3, otherwise this is going to be yet another thing I need to customize when setting up new machines. This has never been a problem for me before and the tiny amount of hard drive space that Husky v4 might save is not worth it. That's why run-node exists.

(Not frustrated, per se, I just think it was the wrong decision to remove it.)

@krnsk0
Copy link

krnsk0 commented Jan 16, 2020

I'm having a similar issue. Hooks run fine when git is called from the command line, but when I use Sourcetree or any other GUI not kicked off from the command line, npx can't be found in PATH. Adding it to the path at the start of each hook script solves things, but doing it in .huskyrc doesn't seem to do anything. (It's not clear that .huskyrc even gets invoked by Sourcetree). Would be great to be able to solve this with .huskyrc

@krnsk0
Copy link

krnsk0 commented Jan 16, 2020

Switching to husky 3.1.0 (which uses run-node) also worked for me, here-- sourcetree runs the hooks, run-node finds my node installation, and commits are blocked as they should be. Still not sure how to get .huskyrc actually run to modify environment vars available in GUI apps in 3.1.0, though.

@k2snowman69
Copy link

k2snowman69 commented Jan 31, 2020

Following up in this issue... is there now a requirement to have npx in your user path? Should we add that as documentation (maybe post-npm install instructions) somewhere?

Or would an option be reverting back to however 3.1.0 executed commands as that seems to be a currently working solution for people?

I'm asking because I'm not sure what the expected resolution is here and if I were to open a PR I'm not sure which option to code.

@krnsk0
Copy link

krnsk0 commented Jan 31, 2020

I think reverting to how 3.1.0 did this (run-node) is probably a better bet; for users who need to support git GUI apps which run a bundled version of git that doesn't have access to the system path, it's the only solution that will work-- even if they have npx installed globally, the their git GUI apps might not be able to find it.

@k2snowman69
Copy link

Oh sorry, this is only via GUI? I'm having this issue via command line... would you like me to create a separate issue? Or just add a comment with similar details as the initial comment?

@mspoerer
Copy link

mspoerer commented Feb 24, 2020

Following up in this issue... is there now a requirement to have npx in your user path? Should we add that as documentation (maybe post-npm install instructions) somewhere?

I would definitely say so. I mean if husky relies on npx, the OS shoud know where to find it. Extending the PATH through ~./huskyrc in the home directory works perfectly fine. Currently I am more concered, that all hooks skip & git proceeds if npx is not provided. @typicode I mean this is definitly a bug. All hooks should fail, if the project setup or OS does not provide, what is needed.

@aniforprez
Copy link

aniforprez commented Apr 8, 2020

I'm having a similar issue where it is skipping hooks because it is detecting a CI environment and thus nothing is installed

Why isn't the obvious solution to allow us to install the hooks manually with some command and provide options? pre-commit does this beautifully and doesn't do magic in the install scripts and leave you hanging dead in the water cause the install didn't function because of n reasons

I'd rather this was "fixed" by giving a manual trigger to install hooks instead of having to deal with the nonsense of randomly having it done during install and sometimes installing the hooks successfully

@chris-dura
Copy link

I've experienced the same problem with husky@4.2.3 and Sourctree 4.0.1 on macOS, but I actually set Sourcetree to use my System git 2.23.0 (and not the embedded git), and npx still can't be found.

@dshuvalov
Copy link

Hi, guys. Try this workaround.

@chris-dura
Copy link

chris-dura commented Apr 17, 2020

@Chypa74 -- Yes, that is a workaround; however, due to some previous comments... I'm not sure that'll actually "fix" Sourcetree.

Regardless, though, I personally feel manually "polluting" a users global environment when only a single project may be using husky is a bit smelly. Also, related to GUIs, the chief audience (again, imho) for git GUIs (like Sourcetree) are typically not tech-savvy developers.

For example, I have a team of a dozen Designers (not Developers) that are committing changes to simple Markdown files in a git repo. Unsurprisingly, not many of them are comfortable in the command line. Using Sourcetree (or any other git GUI) actually makes git accessible and usable for them. They also weren't familiar with writing conventional-commit messages, so using husky and commitlint made it very easy to force them to do it. But, after husky@3.x that setup no longer works when trying to write commit messages in Sourcetree.

That being said...
Should this be fixed in Sourcetree (ie, by properly sourcing the users shell profile)? Probably.
https://jira.atlassian.com/browse/SRCTREE-7184

But, I also think GUI setups are extremely common, and husky was working in those setups, but now it's not :/

@zuzusik
Copy link

zuzusik commented Apr 21, 2020

I consider this as a serious regression for Husky.

Manually creating files to workaround doesn't sound nice, as previously all just worked with single npm install...

@mnn
Copy link

mnn commented Apr 30, 2020

Similar issue, v4 no longer works with IntelliJ IDEA (commit from console does run the hook):

Can't find npx in PATH: /usr/lib/git-core:/home/xxx/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-sdk/emulator:/opt/android-sdk/platform-tools:/opt/android-sdk/tools:/opt/android-sdk/tools/bin:/opt/cuda-10.0/bin:/opt/cuda/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin
Skipping pre-commit hook

npx is in PATH. Downgraded to Husky 1.3.1 which works.

@jeandat
Copy link

jeandat commented May 5, 2020

Hi, guys. Try this workaround.

The workaround worked for me. For others, (just in case as I did missed it first time), the file must be created in your home folder (~/.huskyrc) not at your project root.

@zuzusik
Copy link

zuzusik commented May 13, 2020

@typicode what is your take on this issue?

We are bumping into this constantly with new developers introduced to the team. Previously all they have to do is npm install. Now they also should apply these workarounds in their home folder...

This is very much inconvenient and to quite a degree diminishes everything what husky stays for - automated git hooks installation...

@sholladay
Copy link

Someone should make a fork that uses run-node like the older version of husky did. Then open a PR. If the PR is merged, great. If not, we can start using the fork.

@mateutek
Copy link

Tested on Husky v4 vs v3 and on v4 it works with simplest configuration as said in documentation.
Upgrading to v4 breaks it in Tower client. Wondering if this is problem in Tower or the Husky

@sholladay
Copy link

sholladay commented May 21, 2020

It's a problem in Husky, or macOS, depending on who you choose to blame. Personally, I'm fine with macOS working the way it does by default. It's slightly better security at the cost of convenience. Husky v3 uses the run-node library to find Node, which is designed to work inside of GUI apps on macOS. Husky v4 removed this dependency and is thus broken in all GUI apps on macOS.

tillsanders added a commit to open-election-compass/client that referenced this issue May 26, 2020
Because of this: typicode/husky#639

Signed-off-by: Till Sanders <mail@till-sanders.de>
@tillsanders
Copy link

@typicode Since you appear to be absent from this issue for a few months – are you considering reintroducing run-node to Husky v4 so that GUI clients will work seamlessly once more? I think quite many people would profit from this – me included. And if you approve but are short on time, would you accept a PR on this?

@x-stefan
Copy link

@sholladay Setting up a ~/.huskyrc can solve the issue as well 😉
But this may or may not feasible for all projects. My .huskyrc looks more or less like my .zshrc now.

@sholladay
Copy link

If you're comfortable with that, then great, that's another option. IMO, though, duplicating dotfiles on every machine is gross. Among other problems, you'll have to keep those files in sync, which you may easily forget to do.

@penx
Copy link

penx commented Aug 12, 2020

If you have a project with 3rd party contributors, or a large number of internal contributors, it's not particularly feasible to ask everyone to make sure they have a.huskyrc file set up in order to successfully run git hooks.

The fact that this fails silently means contributors will not be made aware if they missed this step.

@kakaru1331
Copy link

kakaru1331 commented Aug 19, 2020

Thank you, folks.
I've decided to downgrade husky on our project.

I totally agree that this is weird.
Why every people who participate in the project have to set a husky config on their home directory?
I can not answer the question...

I hope we can back to higher version of husky someday. :D

@TrejGun
Copy link

TrejGun commented Sep 27, 2020

Hi! I have this error since macOS 10.15.7. came out

Can't find npx in PATH: /Applications/Xcode.app/Contents/Developer/usr/libexec/git-core:/usr/bin:/bin:/usr/sbin:/sbin
Skipping pre-commit hook

I use ports instead of brew and my npx is in /opt/local/bin/npx and/opt/local/bin is in $PATH

I also have .huskyrc in my project

how can I add fix this?

@sholladay
Copy link

@TrejGun downgrade your Husky to version 3. npm uninstall husky && npm install --save-dev husky@3

@TrejGun
Copy link

TrejGun commented Sep 28, 2020

Thanks
any other options? lets say can i add my #path to somewhere? or make a symlink of npx to #path?
or may be update to 5?

@sholladay
Copy link

Yes, scroll up in this thread. Other people have suggested various alternatives, such as using a .huskyrc file.

@TrejGun
Copy link

TrejGun commented Sep 29, 2020

was magically fixed by itself, probably after system restart

@marcusbesjes
Copy link

marcusbesjes commented Oct 5, 2020

I'm wondering why Husky is skipping in stead of failing when it can't find a command. I use nvm and I don't always have a node command because it doesn't initialize for every new shell.. in any case I also don't want anyone to be able to just waltz by the Husky hooks just because they don't even have Node.js installed right? Shouldn't it just fail in stead of skip?

@jgeurts
Copy link

jgeurts commented Oct 5, 2020

For what it's worth, husky v5 fails when the pre-commit command is not found. It would be nice if the path information for mac GUIs was consistent, but at least the hook can fail when the command is not found.

@smetzdev
Copy link

@TrejGun Same here, updated my macOS Version and noticed that the commits went through pretty fast.
Tested it, so i found out that husky was not running anymore (only if i commited via the VSCode UI, not if i commited via terminal)
Restarting the computer did the trick for me.

@kevindigo
Copy link

Our pre-commit hook was skipped for me when invoking git via vscode on an Ubuntu Linux box. I'm guessing it's the same problem. And it's really frustrating since the whole point of a hook is to have it be automatic and consistent. It should really fail if npx (or whatever) isn't found. It sounds like that might be the case in v5, so I hope that gets published soon.

@typicode
Copy link
Owner

typicode commented Nov 27, 2020

It was a choice before. Allow people who may not have some command(s) on their computer to not be blocked and be able to commit anyway.

The idea was that the CI would catch potential errors if hook didn't run.

It's obviously a trade-off. In teams, you may want to force everyone to have a command.

But as @jgeurts said, unlike v4, husky v5 will block the commit if some command is not found.

edit: clarification of new behaviour

@FuzzyFade
Copy link

@TrejGun downgrade your Husky to version 3. npm uninstall husky && npm install --save-dev husky@3

nice

sug1t0m0 added a commit to sug1t0m0/japanese_population_viewer that referenced this issue Mar 20, 2021
- huskyが動かなかったのでバージョンを変更
- typicode/husky#639
@lucksp
Copy link

lucksp commented Apr 16, 2021

@Alex0007 thanks for the report. It seems that npx isn't in PATH, can you try https://docs.brew.sh/FAQ#my-mac-apps-dont-find-usrlocalbin-utilities or add this in ~/.huskyrc:

PATH="/usr/local/bin:$PATH"

This does help fix VSCode...only if I open VSCode from terminal with code .

Any ideas on why the GitHub Desktop app doesn't get fixed with this update? Still shows .husky/pre-commit: line 4: npx: command not found

This should be re-opened

@Seckiro
Copy link

Seckiro commented Jul 13, 2023

husky - command not found in PATH=/c/program files (x86)/microsoft visual studio/2022/enterprise/common7/ide/commonextensions/microsoft/teamfoundation/team explorer/Git/mingw64/libexec/git-core:/c/program files (x86)/microsoft visual studio/2022/enterprise/common7/ide/commonextensions/microsoft/teamfoundation/team explorer/Git/mingw64/bin:/c/program files (x86)/microsoft visual studio/2022/enterprise/common7/ide/commonextensions/microsoft/teamfoundation/team explorer/Git/mingw64/libexec/git-core:/c/program files (x86)/microsoft visual studio/2022/enterprise/common7/ide/commonextensions/microsoft/teamfoundation/team explorer/Git/usr/bin:

@ChinKX
Copy link

ChinKX commented Dec 4, 2024

For anyone facing issues related to command not found in PATH e.g. gitleaks utility installed from homebrew not found (refer to the screenshot above), I solved it by including the homebrew's binary folder (which contains the binary executables) inside the PATH env variable inside the ~/.config/husky/init.sh. This is how my ~/.config/husky/init.sh looks like:

# Include homebrew's binary folder in the PATH
#
# Note: Please check your `bin` folder as it might not be necessarily in `/opt/homebrew` because the path can be different depends on your Mac chip (Intel or ARM)
#
# You can check it by running this command (`brew --prefix`) in your terminal assuming you already installed homebrew
#
# Reference: https://docs.brew.sh/FAQ#why-should-i-install-homebrew-in-the-default-location
export PATH="$(/opt/homebrew/bin:${PATH}"
# ^^^^^Added this line ^^^^^

# Other setups
#
# Setup NVM
export NVM_DIR="$HOME/.nvm"

[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

# If you have an .nvmrc file, we use the relevant node version
if [[ -f ".nvmrc" ]]; then
    nvm use
fi

References:

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