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

exec doesn't work for executables other than "node" on Windows #1054

Open
jakebailey opened this issue Oct 13, 2023 · 1 comment · May be fixed by #1065
Open

exec doesn't work for executables other than "node" on Windows #1054

jakebailey opened this issue Oct 13, 2023 · 1 comment · May be fixed by #1065

Comments

@jakebailey
Copy link

jakebailey commented Oct 13, 2023

When using fnm exec, only node works; npm and npx don't execute and so I get my global install (or, no install if fnm is my main way of getting Node).

Here's a PowerShell script which shows what I'm referring to:

if (!(Test-Path -Path fnm-windows)) {
    Invoke-WebRequest -URI "https://github.com/Schniz/fnm/releases/download/v1.35.1/fnm-windows.zip" -OutFile "fnm-windows.zip"
    Expand-Archive -Path "fnm-windows.zip" -DestinationPath "fnm-windows"
}

$env:FNM_DIR="$PWD/fnm-windows"

echo "fnm install 8"
./fnm-windows/fnm install 8

echo "node --version"
node --version

echo "npm --version"
npm --version

echo "fnm exec --using=8 -- node --version"
./fnm-windows/fnm exec --using=8 -- node --version

echo "fnm exec --using=8 -- npm --version"
./fnm-windows/fnm exec --using=8 -- npm --version

echo 'fnm exec --using=8 -- node -e "console.log(process.env.PATH)"'
./fnm-windows/fnm exec --using=8 -- node -e "console.log(process.env.PATH)"

The output is:

fnm install 8
Installing Node v8.17.0 (x64)
warning: Version already installed at "C:\\Users\\jabaile\\testing/fnm-windows\\node-versions\\v8.17.0"
node --version
v20.8.0
npm --version
10.1.0
fnm exec --using=8 -- node --version
v8.17.0
fnm exec --using=8 -- npm --version
10.1.0
fnm exec --using=8 -- node -e "console.log(process.env.PATH)"
C:\Users\jabaile\testing/fnm-windows\node-versions\v8.17.0\installation;C:\Program Files\PowerShell\7;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\dotnet\;C:\Program Files\PowerShell\7\;C:\Users\jabaile\scoop\apps\python\current\Scripts;C:\Users\jabaile\scoop\apps\python\current;C:\Users\jabaile\go\bin;C:\Users\jabaile\scoop\apps\rustup\current\.cargo\bin;C:\Users\jabaile\scoop\apps\volta\current\appdata\bin;C:\Users\jabaile\scoop\apps\gcc\current\bin;C:\Users\jabaile\scoop\shims;C:\Users\jabaile\AppData\Local\Microsoft\WindowsApps;C:\Users\jabaile\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\jabaile\AppData\Local\Microsoft\WindowsApps;C:\Users\jabaile\AppData\Local\Programs\Microsoft VS Code Insiders\bin

I suspect that something in the chain isn't handling Window's PATHEXT or something. I'm not super familiar with rust's process handling, but this seems relevant: https://doc.rust-lang.org/std/process/struct.Command.html#platform-specific-behavior

Note on Windows: For executable files with the .exe extension, it can be omitted when specifying the program for this Command. However, if the file has a different extension, a filename including the extension needs to be provided, otherwise the file won’t be found.

So, this is roughly rust-lang/rust#37519 and using https://docs.rs/which/latest/which/ on the command before running would probably fix this. That or, always using a shell on Windows. Not sure what Node itself does here. I know Go handles this for you (https://cs.opensource.google/go/go/+/master:src/os/exec/lp_windows.go), but Rust seems to not want to do this and remain a syscall wrapper.

@jakebailey
Copy link
Author

Note that this probably also affects any other commands run via fnm exec, since fnm is running them directly.

wyatt-herkamp added a commit to wyatt-herkamp/fnm that referenced this issue Oct 26, 2023
wyatt-herkamp added a commit to wyatt-herkamp/fnm that referenced this issue Oct 26, 2023
wyatt-herkamp added a commit to wyatt-herkamp/fnm that referenced this issue Oct 26, 2023
wyatt-herkamp added a commit to wyatt-herkamp/fnm that referenced this issue Oct 26, 2023
wyatt-herkamp added a commit to wyatt-herkamp/fnm that referenced this issue Oct 26, 2023
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

Successfully merging a pull request may close this issue.

1 participant