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 4.x not working with Sublime Merge (GUI) #696

Closed
jeandat opened this issue Mar 24, 2020 · 8 comments
Closed

Husky 4.x not working with Sublime Merge (GUI) #696

jeandat opened this issue Mar 24, 2020 · 8 comments

Comments

@jeandat
Copy link

jeandat commented Mar 24, 2020

I'm using node with nvm and yarn.

I can commit with husky from the command line. But when using a GUI like Sublime Merge I get that kind of error:

The engine "node" is incompatible with this module. Expected version ">=12 <13". Got "13.11.0"

I read and tried what is explained in section "Node version managers" without better results (including .huskyrc file).

My project is configured for Node 12 and has a corresponding .nvmrc file at its root. Node 12 is also the default for the whole system. Plus Node 13 is not installed.

If I remove my husky hooks, everything works fine. If if I downgrade to husky 3.1.0 it works too.

Any idea?

nvm: 0.34.0
node: 12.13.0
yarn: 1.22.4
terminal: zsh 5.3 (x86_64-apple-darwin18.0)
❯ nvm ls
       v10.17.0
       v11.15.0
->     v12.13.0
         system
default -> 12 (-> v12.13.0)
node -> stable (-> v12.13.0) (default)
stable -> 12.13 (-> v12.13.0) (default)
@derekwsgray
Copy link

Exact same issue with GitKraken and WebStorm git clients. None of the workarounds are working for me either.

@thasmo
Copy link

thasmo commented Apr 8, 2020

In addition to https://github.com/typicode/husky#local-commands-huskyrc I removed my system node version; which fixed it for me.

@zuzusik
Copy link

zuzusik commented Apr 22, 2020

Could you folks please chime in in this issue: #639 ?

I believe it's related.

In my opinion, project should move back to run-node. Current workflow with npx seems pretty much not robust for me.

@jeandat
Copy link
Author

jeandat commented May 5, 2020

My bad, the workaround mentioned in the doc 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 (that was my mistake).

@thasmo: Messing with your system node version might not be a good idea as it might be used by some obscur service or expected by others… Seems a bit extreme IMHO.

@jeandat
Copy link
Author

jeandat commented May 5, 2020

@zuzusik Don't know if downgrading to run-node is the right call but I agree that forcing people to add a file in their home folder in order to be able to use a package.json dependency is off. It forces me to either document it and ask coworkers to do a manual task after a clone or automate it. Too invasive.

@typicode
Copy link
Owner

In v3, run-node was used to execute node_modules/.../husky/run.js. However, with package managers improving, it became brittle to rely on some specific structure for node_modules.

In particular, Yarn 2 introduced PnP (which is great) but with it all modules are in one file (pnp.js), so calling node .../husky/run.js wasn't possible anymore.

That's why husky 4 uses package manager to run hooks. Node modules organization is abstracted from husky this way.


Regarding Node version managers, it's another topic. GUI and version managers don't communicate well. There are also many ways to install Node, you can have a coworker using nvm, another one using n, volta or brew.

So having husky support all these tools would be complicated. That's why for GUI users, you can have some init code for your favorite version manager in .huskyrc.

@tomasznguyen
Copy link

I had the same issue with husky 7.0.4 on a Mac with Sublime Merge. Husky worked fine from the CLI but not from Sublime Merge. The problem was that Husky was unable to find yarn and env variables that were defined in ~/.zshrc.

The fix was to create the file ~/.huskyrc.

# ~/.huskyrc
source ~/.zshrc

And in /.zshrc, I load nvm (see https://typicode.github.io/husky/#/?id=command-not-found).

# ~/.zshrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

@q-rault
Copy link

q-rault commented May 22, 2022

Thank you @tomasznguyen, worked like a charm for me with husky 8.0.1 !

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

7 participants