Schniz / fnm

🚀 Fast and simple Node.js version manager, built in Rust
https://fnm.vercel.app
GNU General Public License v3.0
17.57k stars 446 forks source link

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

Open rfgamaral opened 3 years ago

rfgamaral commented 3 years ago

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 commented 3 years ago

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

eval "$(fnm env)"

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

rfgamaral commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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

Schniz commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 1 year ago

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

ImBIOS commented 1 year ago

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 commented 1 year ago

same here same issue fnm command not found

alumni commented 1 year ago

@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 commented 2 months ago

Potential workaround/solution https://github.com/Schniz/fnm/issues/668#issuecomment-2233615946

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