fnm icon indicating copy to clipboard operation
fnm copied to clipboard

Can't get Husky v6 to work with fnm

Open rfgamaral opened this issue 5 years ago • 13 comments

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...

rfgamaral avatar Apr 10 '21 10:04 rfgamaral

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

eval "$(fnm env)"

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

Schniz avatar Apr 10 '21 10:04 Schniz

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 avatar Apr 10 '21 12:04 rfgamaral

@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?

rfgamaral avatar Apr 10 '21 15:04 rfgamaral

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

Schniz avatar Apr 10 '21 18:04 Schniz

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?

Schniz avatar Apr 10 '21 18:04 Schniz

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 avatar Apr 11 '21 09:04 rfgamaral

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')"

rfgamaral avatar Apr 14 '21 11:04 rfgamaral

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.

alumni avatar May 26 '21 11:05 alumni

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

jstcki avatar Feb 15 '23 10:02 jstcki

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

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

ImBIOS avatar Jun 25 '23 14:06 ImBIOS

same here same issue fnm command not found

Robokishan avatar Jul 04 '23 12:07 Robokishan

@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.

alumni avatar Jul 04 '23 13:07 alumni