Closed Alex0007 closed 3 years ago
@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"
can you try https://docs.brew.sh/FAQ#my-mac-apps-dont-find-usrlocalbin-utilities
This one worked for me
@sholladay how was Node installed? If it was with homebrew, have you tried the suggested command?
Also are you using Husky 4.0.9?
@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.)
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
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.
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.
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.
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?
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.
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
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.
Hi, guys. Try this workaround.
@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 :/
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
...
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.
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.
@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...
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.
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
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.
@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?
Anyone know of any good alternatives to husky that don't have this problem? And are actively maintained.
This bit me recently. I am not aware of a change I made to trigger it, but maybe it was a macOS update. Anyhow, I downgraded to v3.1 for now. Our environment has many many repos, so asking devs to add things to user folder or path for one or a few repos isn't a good solution for us.
That's a long form/explanation of a thumbs up on this issue getting fixed so it just works with npm i
for a solution using husky.
It is probably time for a community fork that is based on v3, or that at least uses run-node
.
Was bitten by this as well when using Fork. Wasn't even aware until recently. Hooks run fine when doing git commit -m
via Terminal, but not via Mac GUI app.
Husky having issues in all GUI Git tools I have tried for OSX including Tower, Gitkraken. CLI hooks run without any problem.
The solution is to downgrade to Husky v3.
@Alex0007 maybe you could edit the original issue comment to mention the solution so it's more visible to people?
@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.
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.
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.
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
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?
@TrejGun downgrade your Husky to version 3. npm uninstall husky && npm install --save-dev husky@3
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?
Yes, scroll up in this thread. Other people have suggested various alternatives, such as using a .huskyrc
file.
was magically fixed by itself, probably after system restart
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?
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.
@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.
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.
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
@TrejGun downgrade your Husky to version 3.
npm uninstall husky && npm install --save-dev husky@3
nice
@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
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:
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
When making commit in VSCode GUI
Everything works fine when making commit from VSCode terminal.
Version 3 works fine. Sample output from v3: