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

Can't get Husky v6 to work with fnm #428

Open
rfgamaral opened this issue Apr 10, 2021 · 13 comments
Open

Can't get Husky v6 to work with fnm #428

rfgamaral opened this issue Apr 10, 2021 · 13 comments

Comments

@rfgamaral
Copy link

I use ZSH and here's how I set up fnm on ~/.zshrc:

eval "$(fnm env --shell=zsh --use-on-cd --log-level=quiet)"

Now I'm trying to set up Git hooks with the latest Husky version, but I can't get them to work. If I commit from my shell, everything works as expected. If I commit from an application, I get this:

image

Then I followed Husky's instructions to fix this issue, and I have added fnm env --shell=zsh to ~/.huskyrc, but then I got this

image

Not sure how to fix this...

@Schniz
Copy link
Owner

Schniz commented Apr 10, 2021

What do you mean "from an application"? A CI step?
Try

eval "$(fnm env)"

Another option is to fnm exec -- npx ...

@rfgamaral
Copy link
Author

From a desktop application. I've used SmartGit in the examples above. I'll try the eval one when possible, and report back.

I can't do the other suggestion because that would change it for the whole team and not everyone uses fnm.

@rfgamaral
Copy link
Author

@Schniz That solved it, and it makes sense, it was stupid of me to do it without eval 🤦‍♂️

However, I had a different problem after that... You see, I'm using fnm inside WSL2, and SmartGit (and Fork) on Windows, with wslgit to call git inside WSL, which in turn will use fnm. The problem is the following line generated by fnm env:

export PATH="/tmp/fnm_multishell_20645_1618069942301/bin":$PATH

This is problematic because $PATH contains a lot of Windows paths with spaces, and that command breaks. I'm wondering if you could change it to:

export PATH="/tmp/fnm_multishell_20645_1618069942301/bin:$PATH"

I simulated this on my .huskyrc file (instead of fnm env and it finally worked without issues.

Any chance you can make that change so that spaces in $PATH work correctly?

@Schniz
Copy link
Owner

Schniz commented Apr 10, 2021

Hmm makes sense! What do you say about contributing it? Should be fairly easy and you will leave a mark 😃

@Schniz
Copy link
Owner

Schniz commented Apr 10, 2021

I can't do the other suggestion because that would change it for the whole team and not everyone uses fnm.

Let's convince them to use it 😈😈 why won't they use fnm? Is something missing or does not work for them?

@rfgamaral
Copy link
Author

Hmm makes sense! What do you say about contributing it? Should be fairly easy and you will leave a mark 😃

I looked at the code, but I have not idea what to do, I don't know Rust, and unfortunately I don't have much time to dig into the source code now :(

Let's convince them to use it 😈😈 why won't they use fnm? Is something missing or does not work for them?

I don't know, never had that conversation. I believe some use it, some use something else, and some probably use nothing. I've recommended it in the past, but I have no idea who started using it and who didn't 😅

@rfgamaral
Copy link
Author

FYI, I have temporarily solved this issue on my side by loading fnm like this:

eval "$(fnm env --shell=zsh --log-level=quiet | sed -e 's/PATH="\(.*\)":\$PATH/PATH="\1:$PATH"/g')"

@alumni
Copy link

alumni commented May 26, 2021

FYI, I have temporarily solved this issue on my side by loading fnm like this:
eval "$(fnm env --shell=zsh --log-level=quiet | sed -e 's/PATH="\(.*\)":\$PATH/PATH="\1:$PATH"/g')"

I also did something similar as a workaround for Git Bash in #390.

@jstcki
Copy link

jstcki commented Feb 15, 2023

Putting eval "$(fnm env --log-level=quiet)" in ~/.huskyrc (not ~/.zshrc) worked for me.

@ImBIOS
Copy link

ImBIOS commented Jun 25, 2023

eval "$(fnm env --shell=zsh --log-level=quiet | sed -e 's/PATH="(.*)":$PATH/PATH="\1:$PATH"/g')"

/.huskyrc: line 2: fnm: command not found

@Robokishan
Copy link

same here same issue fnm command not found

@alumni
Copy link

alumni commented Jul 4, 2023

@ImBIOS @Robokishan This is not an fnm issue, but rather how you configured husky. You may want to take a look at the husky docs: https://typicode.github.io/husky/troubleshooting.html#command-not-found

I have this in my ~/.huskyrc file:

eval "$(fnm env)"

If husky is not able to find fnm, you should follow the procedure specific to your OS to add it to the path (or do it in .huskyrc).

This issue should be closed.

@nemchik
Copy link

nemchik commented Jul 17, 2024

Potential workaround/solution #668 (comment)

Note on the info above: ~/.huskyrc is deprecated. Use ~/.config/husky/init.sh with newer versions of husky.

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