fnm
fnm copied to clipboard
Git Bash issues with CLI tools
The setup for Git Bash (Windows) cannot run cli tools that are installed using npm install -g
.
$ fnm env
export PATH="C:\\Users\\XXX\\AppData\\Local\\Temp\\fnm_multishell_15584_1612875966568":$PATH
export FNM_MULTISHELL_PATH="C:\\Users\\XXX\\AppData\\Local\\Temp\\fnm_multishell_15584_1612875966568"
...
Running node works:
node -v
v15.8.0
But bash is somehow confused about the actual path:
$ which node
/c/Users/XXX/Work/neo-backend/\Users\XXX\AppData\Local\Temp\fnm_multishell_17812_1612875949353/node
And if I use any cli tool installed with npm, I'll get this:
$ npm install -g yarn
added 1 package
$ yarn
node:internal/modules/cjs/loader:928
throw err;
^
Error: Cannot find module 'C:\Program Files\Git\Users\XXX\AppData\Local\Temp\fnm_multishell_17812_1612875949353\node_modules\yarn\bin\yarn.js'
This can be fixed by making sure that the PATH
env variable is using Git-Bash paths:
export PATH="/c/Users/XXX/AppData/Local/Temp/fnm_multishell_15584_1612875966568":$PATH
I've been playing with fnm
today and I must say it's quite fast, I like it a lot ;)
I made a workaround for this invalid PATH
issue. Here's my startup (.bashrc
etc) script:
eval $(fnm env | sed 1d)
export PATH=$(cygpath $FNM_MULTISHELL_PATH):$PATH
if [[ -f .node-version || -f .nvmrc ]]; then
fnm use
fi
what is cygpath
😨 can we fix it upstream?
I mean, currently the path is windows-like if you are on a Windows build, maybe it should differ based on the shell instead? And if that so, should we use cygpath
? Will it be supported on every Bash on Windows? or should we differentiate between Bash and Git Bash?
On MSYS and CygWin, cygpath
converts between Windows <-> POSIX paths (replaces the path separators and drive letter: X:\some\path
<-> /x/some/path
), but might also map some common paths like /tmp
~~or home~~ or system folders (/usr/bin
is C:\Program Files\Git\usr\bin
. In this specific case:
C:\Users\XXX\AppData\Local\Temp\fnm_multishell_9452_1612950115921
-> /tmp/fnm_multishell_9452_1612950115921
Git for Windows provides a stripped-down version of MSYS. The thing is that MSYS internally uses POSIX paths, and it maintains its own PATH
variable in the POSIX format. It also converts CLI arguments - when executing fnm --fnm-dir ~/.fnm
, fnm
will think it's called like this: fnm.exe --fnm-dir C:\Users\XXX\.fnm
.
On Windows, every cli command that is installed from node has two versions, e.g. yarn
(shell script) and yarn.cmd
(Windows Command Script). If node is started from Bash, spawning a yarn
process from node will call the shell script, if it's started somehow else, it calls the cmd
file.
I don't think zsh
, fish
or bash
can ever use Windows paths. At the moment, you can only run them on Windows if you use MSYS, CygWin and WSL. I am not aware of any "native" port (well, MSYS is the only one that is running Windows-native executable code but with this path conversion).
PowerShell is probably the only one that adapts to the OS (POSIX paths on Linux).
Was this issue fixed? I've been unable to get fnm working in Git Bash (it works fine in CMD and PowerShell). Even the command 'node' isn't found.
Upon checking the output of fnm env
, fnm tries to mix Windows style paths and unix style paths, which can be solved with cygpath as @alumni mentions.
I've been playing with
fnm
today and I must say it's quite fast, I like it a lot ;)I made a workaround for this invalid
PATH
issue. Here's my startup (.bashrc
etc) script:eval $(fnm env | sed 1d) export PATH=$(cygpath $FNM_MULTISHELL_PATH):$PATH if [[ -f .node-version || -f .nvmrc ]]; then fnm use fi
Thanks so much for this workaround; it worked perfectly for me.
I've been playing with
fnm
today and I must say it's quite fast, I like it a lot ;)I made a workaround for this invalid
PATH
issue. Here's my startup (.bashrc
etc) script:eval $(fnm env | sed 1d) export PATH=$(cygpath $FNM_MULTISHELL_PATH):$PATH if [[ -f .node-version || -f .nvmrc ]]; then fnm use fi
Just a note. eval "$(fnm env | sed 1d)"
works for me but eval $(fnm env | sed 1d)
doesn't. Thanks so much for this workaround.
I can confirm that everything is fine on Git Bash, no need for workarounds:
eval "$(fnm env --use-on-cd)"
Confirmed same: as of v1.34.0, git-bash in Win10 works as designed and documented, making workarounds moot.