Skip to content

fnm download snippet fails on Windows #7487

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

Open
MikeMcC399 opened this issue Feb 11, 2025 · 24 comments
Open

fnm download snippet fails on Windows #7487

MikeMcC399 opened this issue Feb 11, 2025 · 24 comments

Comments

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented Feb 11, 2025

URL:

https://nodejs.org/en/download

Browser Name:

Microsoft Edge

Browser Version:

133.0.3065.59 (Official build) (64-bit)

Operating System:

Windows 11 24H2 10.0.26100.3037

How to reproduce the issue:

Steps

Copy and run the download instructions from https://nodejs.org/en/download for Windows using fnm with npm in a PowerShell terminal:

# Download and install fnm:
winget install Schniz.fnm

# Download and install Node.js:
fnm install 22

# Verify the Node.js version:
node -v # Should print "v22.13.1".

# Verify npm version:
npm -v # Should print "10.9.2".

Expectation

The snippet should run without error.

The implicit assumption of offering a "Copy to clipboard" button with a label "PowerShell" is that the shell script can be copied and run as-is.

In fact, a user needs to visit https://github.com/Schniz/fnm/blob/master/README.md and navigate a complex set of instructions to set up fnm to work on Windows.

Actual

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\Users\mikem> # Download and install fnm:
PS C:\Users\mikem> winget install Schniz.fnm
Found Fast Node Manager [Schniz.fnm] Version 1.38.1
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Successfully verified installer hash
Extracting archive...
Successfully extracted archive
Starting package install...
Command line alias added: "fnm"
Successfully installed
PS C:\Users\mikem>
PS C:\Users\mikem> # Download and install Node.js:
PS C:\Users\mikem> fnm install 22
Installing Node v22.13.1 (x64)
PS C:\Users\mikem>
PS C:\Users\mikem> # Verify the Node.js version:
PS C:\Users\mikem> node -v # Should print "v22.13.1".
node : The term 'node' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ node -v # Should print "v22.13.1".
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (node:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\mikem>
PS C:\Users\mikem> # Verify npm version:
PS C:\Users\mikem> npm -v # Should print "10.9.2".
npm : The term 'npm' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ npm -v # Should print "10.9.2".
+ ~~~
    + CategoryInfo          : ObjectNotFound: (npm:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Related

@avivkeller
Copy link
Member

avivkeller commented Mar 21, 2025

IIUC we need to add the following line:

'fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression' >> $PROFILE

Does executing that fix the issue?

@avivkeller avivkeller moved this from 📋 Backlog to 🏗 In progress in Node.js Website Mar 22, 2025
@avivkeller avivkeller self-assigned this Mar 22, 2025
@avivkeller
Copy link
Member

No response from OP, I'm going to verify this solution today, and if it does work, I'll send a PR accordingly

@MikeMcC399
Copy link
Contributor Author

@avivkeller

Sorry. I somehow missed your post. I will see if I can test your solution.

@MikeMcC399
Copy link
Contributor Author

MikeMcC399 commented Apr 3, 2025

@avivkeller

Unfortunately just adding

'fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression' >> $PROFILE

to the script does not solve all the issues. It seems that there are multiple barriers to providing a script which runs error free in one single invocation on a freshly installed Windows system and sets up fnm and Node.js.

I don't know if there is any simple solution to this.

  1. After installing Schniz.fnm it says:

    Command line alias added: "fnm"
    Path environment variable modified; restart your shell to use the new value.

  2. Attempting to execute 'fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression' >> $PROFILE if there is no PowerShell profile available results in the error "Could not find a part of the path" ... "DirectoryNotFoundException"

  3. Simply creating a profile according to https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.5#how-to-create-a-profile as follows, allows the fnm command to be added to the profile, however when PowerShell tries to use this it reports "WindowsPowerShell\Microsoft.PowerShell_profile.ps1 is not digitally signed" ... "PSSecurityException"

    if (!(Test-Path -Path $PROFILE)) {
    New-Item -ItemType File -Path $PROFILE -Force
    }
  4. If node -v is executed without restarting the terminal then the error node : The term 'node' is not recognized as the name ... is displayed. This issue goes away if the PowerShell terminal is restarted.

Edit: The above refers to testing on Windows 11 24H2.

@avivkeller
Copy link
Member

avivkeller commented Apr 3, 2025

wow! There are several levels to this issue. @Schniz do you happen to have a simple script, assuming the user is installing on a PS7+ shell?

@avivkeller
Copy link
Member

avivkeller commented Apr 6, 2025

The way I see it,

On the + side:

  • It's supported on all distributions
  • 3.2m+ users
  • Actively maintained and regularly updated

On the - side (for Windows only):

  • Different instructions depending on the terminal in use, and the version of said terminal
  • Troubleshooting requires familiarity with Windows-specific quirks
  • Not beginner-friendly compared to other methods

(Bullets 1 and 2 refer to https://github.com/Schniz/fnm/tree/master?tab=readme-ov-file#powershell)

@MikeMcC399
Copy link
Contributor Author

Microsoft recommends other Node.js version managers:

See https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-windows

@ovflowd
Copy link
Member

ovflowd commented Apr 7, 2025

Microsoft recommends other Node.js version managers:

See https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-windows

FYI nvm-windows is on maintenance mode and being superseded by https://github.com/coreybutler/nvm-windows/wiki/Runtime

@avivkeller avivkeller removed their assignment Apr 7, 2025
@MikeMcC399
Copy link
Contributor Author

@avivkeller / @ovflowd

If there is any discussion about replacing fnm as a Windows recommendation, that should probably be done under a different issue. (FWIW: I actually use an older version of [email protected] for my own daily work.)

This issue should really be focused on getting a working set of instructions to use fnm for Windows.

If there is no automated way to do this for Windows, then perhaps just some extra text would need to be added to the instructions.

Something like:

"# Visit https://github.com/Schniz/fnm for additional setup instructions"

# Download and install fnm:
winget install Schniz.fnm

# Visit https://github.com/Schniz/fnm for additional setup instructions

# Download and install Node.js:
fnm install 22

# Verify the Node.js version:
node -v # Should print "v22.13.1".

# Verify npm version:
npm -v # Should print "10.9.2".

@avivkeller
Copy link
Member

# Visit https://github.com/Schniz/fnm for additional setup instructions

That would work I suppose, but IMHO we shouldn't outsource information for installing content. @ovflowd WDYT about removing fnm from Windows (but not POSIX, as it works fine for those), and moving it to the All download methods page?

@ovflowd
Copy link
Member

ovflowd commented Apr 7, 2025

Afaik we are strongly opposed on redirection. We must provide a minimal set of instructions. We of course cannot cover every single terminal app/emulator people are using hence we need to make drawbacks or decide which environment we assume users are. The same applies for Linux. We cant provide support to the whole umbrella of the shell systems out there 😅

@avivkeller
Copy link
Member

avivkeller commented Apr 14, 2025

@nodejs/nodejs-website
@nodejs/package-maintenance

👍 — Support removing fnm from the Windows installation instructions.

👎 — Oppose removing fnm; prefer to improve the existing instructions.

😕 - Move fnm from an official installation to a community installation; improve the existing instructions.

🚀 - Neutral

❤️ - Reach out to the maintainer of the project for additional insight.

@MattIPv4
Copy link
Member

Move fnm from an official installation to a community installation

Why would this be done, what criteria that fnm originally met does it no longer meet?

@MattIPv4
Copy link
Member

MattIPv4 commented Apr 15, 2025

@avivkeller
Copy link
Member

Why would this be done, what criteria that fnm originally met does it no longer meet?

None, I was just listed all possible scenarios

@bjohansebas
Copy link
Member

With this correction in the command, I confirm it's working :)

Schniz/fnm#1411

@avivkeller
Copy link
Member

That doesn't solve our issue, however, which is that the command in that PR needs to be added to shell specific config file, which can be poor DX for users to find.

IMHO @Schniz should make it part of the installation that the profile be updated, it would solve all these issues.


By the way, thanks for voting, it's nice to see where everyone is at :-)

@MattIPv4
Copy link
Member

Yes, +1 that this should be part of the winget installation to set the profile up appropriately automatically for the user -- the fnm README actually implies that this will be done, the winget install instructions do not point the user to the shell setup unlike other installation methods.

@Schniz
Copy link

Schniz commented Apr 15, 2025

I am not maintaining the choco or winget installers, nor I know how they work as I haven’t used Windows for more than a decade. They are not a part of the fnm repo too. Contributions to these installers are welcome. If you know any way of moving the sources of these installations to the fnm repo, we could actually own it and have changelogs there etc.

Let me know exactly how you want to act on this, and we can fix it. I’m not a part of that ecosystem so it would be helpful to get your help on that ;-)

@Schniz
Copy link

Schniz commented Apr 15, 2025

What I can say about the homebrew ecosystem (aka macOS) is that it’s not allowed to set up profile in homebrew formulas afaik. Maybe winget is the same. We can maybe create “fnm init” that’ll setup fnm for all known shells. What do you think about it?

@MattIPv4
Copy link
Member

I'm also not in the Windows world, but my gut says the best approach might be to land Schniz/fnm#1018 or some version thereof, so that you have your own install script that folks can run similar to what you recommend for Linux/macOS -- that script can then do the full install including the profile, and the winget etc. can remain the "same" as homebrew etc. in just installing the tool itself?

@avivkeller
Copy link
Member

avivkeller commented Apr 15, 2025

Heya everyone! As @MattIPv4 said, landing that script (or some variant of) would be ideal. The WinGet installers can be set to execute said script if that's the direction you are going for, but one way or another, an automated install significantly improves DX

@Schniz
Copy link

Schniz commented Apr 17, 2025

I’ll try to merge the PR mentioned next week. I’m currently celebrating Passover with my family but I understand the importance and I do it once I’m back

@ovflowd
Copy link
Member

ovflowd commented Apr 17, 2025

I’ll try to merge the PR mentioned next week. I’m currently celebrating Passover with my family but I understand the importance and I do it once I’m back

Appreciate your time here, @Schniz!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🏗 In progress
Development

No branches or pull requests

6 participants