Schniz / fnm

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

the mistake about Shell Setup #1110

Open liiiiiiiiiiiir opened 6 months ago

liiiiiiiiiiiir commented 6 months ago

I installed fnm with cargo, used powershell.

But after I add the following to the end of my profile file: fnm env --use-on-cd | Out-String | Invoke-Expression

the mistake would come out: QQ截图20240421181053

I'm sure the env var is corrent

Schniz commented 6 months ago

it says fnm is not available. Maybe the initialization happens before cargo is added to PATH?

liiiiiiiiiiiir commented 6 months ago

it says fnm is not available. Maybe the initialization happens before cargo is added to PATH?

nonono, I installed the cargo first, and then I ran cargo install fnm

liiiiiiiiiiiir commented 6 months ago

it says fnm is not available. Maybe the initialization happens before cargo is added to PATH?

Hello, this error has been resolved. When there is Chinese in the environment variable, fnm env --use-on-cd will output garbled results. I'm sorry about this. So I was wondering if it's possible to add a option to set encoding format. And I just tested Chinese, I don't know if other non English languages have this problem

Schniz commented 6 months ago

Can you please attach the output you get? So we can escape it properly 🙏

liiiiiiiiiiiir commented 6 months ago

Can you please attach the output you get? So we can escape it properly 🙏 When fnm is installed on the C drive, it will output the following information when used QQ截图20240422181237 QQ截图20240422181223

Afterwards, I moved FNM to the full English path, and there was no problem using FNM, but the installation path of the node still had garbled characters QQ截图20240422180346 The folder below is a directory automatically created by FNM when downloading nodes due to garbled characters

KonradSuli commented 6 months ago

Hey.

Similar issue here, almost opened a new ticket.

For me, my userprofile directory on windows contains the letter 'á': C:\Users\Konrád. I installed fnm using winget and powershell, and the results were pretty bad.

winget install Schniz.fnm ... Successfully installed

To the environment variables it added C:\Users\Konrád\AppData\Local\Microsoft\WinGet\Packages\Schniz.fnm_Microsoft.Winget.Source_8wekyb3d8bbwe

After fixing it manually I reloaded the path $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") Then installed node fnm install 20 This created the node installation under a new user folder: C:\Users\KonrÔöť├şd\AppData\Roaming\fnm

Then I tried playing around a bit more:

PS C:\Projects\t90dct\t90dct-stats\frontend> fnm install 20
Installing Node v20.12.2 (x64)
warning: Version already installed at "C:\\Users\\KonrÔöť├şd\\AppData\\Roaming\\fnm\\node-versions\\v20.12.2"
PS C:\Projects\t90dct\t90dct-stats\frontend> fnm env --use-on-cd | Out-String | Invoke-Expression
fnm:
Line |
  10 |  function global:Set-FnmOnLoad { fnm use --silent-if-unchanged }
     |                                  ~~~
     | The term 'fnm' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS C:\Projects\t90dct\t90dct-stats\frontend> fnm env --use-on-cd | Out-String | Invoke-Expression
fnm: The term 'fnm' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS C:\Projects\t90dct\t90dct-stats\frontend> winget
winget: The term 'winget' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

After trying fnm env, it kinda killed my PATH as it is, and I had to reload it. Trying to use fnm env from the startup powershell script results in the same error.

I then tried using it from a terminal with administrator priviliges just to see what would happen. After installing fnm there and trying to fnm use it, and fnm env ... I now have 2 more folders where they should not be:

C:\Users\Konr├íd\AppData\Local\fnm_multishells C:\Users\Konr├ö├Â┼ąÔöť┼čd\AppData\Roaming\fnm

So yeah... it is kind of broken, not only with chinese characters. Probably something something windows' own character encoding messing with stuff.

Schniz commented 6 months ago

I haven’t used windows in almost 10 years. Would be great to get your assistance in what needs to change in the fnm env output 🙏

KonradSuli commented 6 months ago

Sadly fnm env's output does not seem to be the only thing broken. I tried uninstalling via winget and that also failed. The env variable path that was set was also incorrect. It's probably the handling of the OS path strings in general that's the problem.

That said in the fnm env case specifically this line is to blame: $env:FNM_DIR = "C:\Users\Konr├ö├Â┼ąÔöť┼čd\AppData\Roaming\fnm"

My rust and knowledge on character encodings are far from anywhere close to even understand what needs to be changed, but I'll take a look when my time permits.

Edit: Also I just noticed that some \fnm_multishells directories were created in the correct place, making me even more confused

ralphcorrigan commented 4 months ago

Hi, bumping on this issue as it is recent and seems related, but I'm getting some similar issues with this. It definitely was working on windows as I've successfully used it previously, but it now isn't. When trying the install step in PowerShell I get:

PS C:\> fnm env --use-on-cd | Out-String | Invoke-Expression
fnm : error: Can't infer shell!
At line:1 char:1
+ fnm env --use-on-cd | Out-String | Invoke-Expression
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (error: Can't infer shell!:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

fnm can't infer your shell based on the process tree.
Maybe it is unsupported? we support the following shells:
* bash
* zsh
* fish
* powershell
* cmd
Invoke-Expression : Cannot bind argument to parameter 'Command' because it is an empty string.
At line:1 char:36
+ fnm env --use-on-cd | Out-String | Invoke-Expression
+                                    ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:PSObject) [Invoke-Expression], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.InvokeExpressionCo 
   mmand
ralphcorrigan commented 4 months ago

Just further on this - the line fnm env --use-on-cd | Out-String | Invoke-Expression has been added to the profile, which is in the correct location...

Schniz commented 4 months ago

What fnm version are you on?

ralphcorrigan commented 4 months ago

Hi Gal 1.37.1

Ralph

On 05/07/2024 20:34, Gal Schlezinger wrote:

What fnm version are you on?

-- Reply to this email directly, view it on GitHub [1], or unsubscribe [2]. You are receiving this because you commented.Message ID: @.***>

Links:

[1] https://github.com/Schniz/fnm/issues/1110#issuecomment-2211326398 [2] https://github.com/notifications/unsubscribe-auth/AOO4TCTDGI3HXKAKG7FGB2LZK3YLZAVCNFSM6AAAAABGRIBCDCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJRGMZDMMZZHA

Schniz commented 4 months ago

interesting. would be great to understand what is special about your setup. i have some tests and i need to know how to repro 🙏

ChromaLTS commented 2 months ago

Same problem for me -___- and its the same with the special characters.

My username on my pc has a ü. The path winget made changed it to Ã1⁄4 and changing the path manually made it so I can run fnm. I will update here again if I run into more problems.

If I can help with anything eg. setting up to repro then I will gladly help ^^

Edit 1 Yep another thing isnt working. something seems to be up with running -> fnm env --use-on-cd | Out-String | Invoke-Expression

When i run this line it just accepts it and returns nothing. Then when i try to call fnm its no longer in path. I ran "fnm env --use-on-cd" to try and look at its result and it doesnt look like it gets the ü wrong here. 😕

MrOxMasTer commented 2 months ago

https://github.com/Schniz/fnm/issues/1232

MrOxMasTer commented 2 months ago

interesting. would be great to understand what is special about your setup. i have some tests and i need to know how to repro 🙏

There is nothing special about customizing it. The issue is the username, which has characters other than English. 90% of tools designed for programmers (especially on windows) suffer from this problem. It's just not so obvious. Either it works, but incorrectly (as in this case), or it simply refuses to work

you can check this by using the same command fnm env ... removing the last | ... and see what non-existent paths fnm writes.

First of all: it's just inconvenient to write such a thing in each console configuration, because you can open any console in the terminal and the tool won't work (for example in vs code).

Second: unusual behavior when there is no content in .node-version file. At first I didn't understand why in windows terminal node version is displayed, but here it just resets, but it can be fixed I think, but maybe so in nvm (never checked for an empty file nvm itself). Just pointing that out

image image

with the absence of the .node-version file or writing a version to it, everything works well

MrOxMasTer commented 2 months ago

I'm sure the env var is corrent

I suggest you just reinstall windows if you can and change your username to English letters. I guarantee you will breathe a lot easier. I reinstalled and everything worked right away and not only that

m-aliozkaya commented 2 months ago

I encountered an issue when I attempted to use the link provided. Windows requires a terminal reload to resolve the problem.

  1. First install fnm
  2. Open new terminal
  3. It works.

image

alexschlueter commented 1 month ago

Hi, I think I found a good fix for this: You need to change the output encoding of Powershell to utf8 in order for Out-String to not garble special characters, i.e. in your profile write

[Console]::OutputEncoding = [System.Text.Encoding]::utf8
fnm env --use-on-cd --shell power-shell | Out-String | Invoke-Expression

Maybe the instructions in the README should be updated to this. I don't know if changing the output encoding in your profile breaks any other programs, so maybe the general recommendation should be to save the current value of OutputEncoding to a variable, execute the above and then change back to the stored encoding.

princeyaro commented 2 weeks ago

Good day ALL, please can someone help with the step-by-step guide on how to go from f# installs fnm (Fast Node Manager) winget install Schniz.fnm

configure fnm environment

fnm env --use-on-cd | Out-String | Invoke-Expression

download and install Node.js

fnm use --install-if-missing 20

verifies the right Node.js version is in the environment

node -v # should print v20.18.0

verifies the right npm version is in the environment

npm -v # should print 10.8.2

I keep getting error when I run this fnm env --use-on-cd --shell power-shell | Out-String | Invoke-Expression

this is the error: C:\Windows\system32>fnm env --use-on-cd --shell power-shell | Out-String | Invoke-Expression 'Out-String' is not recognized as an internal or external command, operable program or batch file.

Any advise on how to go about this

87AndCry commented 2 weeks ago

this is the error: C:\Windows\system32>fnm env --use-on-cd --shell power-shell | Out-String | Invoke-Expression 'Out-String' is not recognized as an internal or external command, operable program or batch file.

Any advise on how to go about this

You appear to be in CMD rather than PowerShell.