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

ERROR open \settings.txt: The system cannot find the file specified. #945

Closed
lloydjatkinson opened this issue Mar 15, 2023 · 24 comments
Closed

Comments

@lloydjatkinson
Copy link

lloydjatkinson commented Mar 15, 2023

Issue:
After installing nvm (from WinGet in this case) and before restarting the terminal, attempting to use nvm will fail.

Now, you might think that restarting the terminal is a simple action the user can do but when you are trying to automate the installation of a bunch of apps and developer tools, it's not a viable solution to restart the terminal.

Running nvm at this point will fail with the expected error:

nvm: The term 'nvm' is not recognised as the name of...

So the next step would be to invoke nvm directly, which fails with this error:

PS C:\Users\User> C:\Users\User\AppData\Roaming\nvm\nvm.exe install latest

ERROR open \settings.txt: The system cannot find the file specified.

How To Reproduce:

  1. Use WinGet to install nvm winget install --id=CoreyButler.NVMforWindows -e
  2. Attempt to run nvm directly as the terminal session will not have the updated %PATH%
  3. Get weird error about missing settings.txt

Expected Behaviour:

It should be possible to automate the installation of developer tooling including nvm without needing to restart the terminal and thus no longer be possible to automate.

Screenshots:
image

Desktop:

  • OS: Windows 11 - not tried on Windows 10, probably the same.

Additional context:

If this is some hard to fix error, could it be possible to add an argument to nvm which accepts a path of the settings file to use?

@coreybutler
Copy link
Owner

I'm not sure how winget is doing things (I don't maintain that installer). I typically recommend people follow the manual installation guide when attempting to automate installation.

In this case, you may just need to touch the settings.txt file or assure it can be read. Your screenshot shows the settings file, so I'm not sure why it's not recognizing it.

Is this a US English locale?

@julian-shermis
Copy link

julian-shermis commented Mar 16, 2023

Corey, I'm also noticing the same issue and I've manually installed it. I've tried to use the command line as an administrator and still no luck.

EDIT: I resolved the issue, and this is probably the issue that he is having too. the name of the file shouldn't be settings.txt it should just be named settings with a txt file type

@coreybutler
Copy link
Owner

coreybutler commented Mar 19, 2023

It should work with the .txt extension. However; it's important the the file be saved in UTF-8 format. If it's a different format, it may not be recognized.

@JaxCoder
Copy link

my settings.txt was created by the installer. I checked that it is UTF-8 and it is.
ERROR open \settings.txt: The system cannot find the file specified.
maybe its just being shown wrong, but I see "\settings.txt" and it makes me think it's looking for "\settings.txt", which is different than ".\settings.txt" so if the error is correct, it's trying to look for settings.txt in the root of the drive.

@lloydjatkinson
Copy link
Author

I'm on English UK ("International").

so if the error is correct, it's trying to look for settings.txt in the root of the drive.

I had the same thought too.

@coreybutler
Copy link
Owner

Please check the value of the NVM_HOME environment variable, which should not be empty. With manual installations (which the winget installer is likely based on), this value may not be set. If that's the case, then @JaxCoder is likely correct that it's confusing the path to the settings file. If there is no NVM_HOME, the settings path is not generated correctly (https://github.com/coreybutler/nvm-windows/blob/master/src/nvm.go#L49).

coreybutler added a commit that referenced this issue Apr 11, 2023
…h new encoding for settings (forcing UTF-8).
@cryptiklemur
Copy link

This is also happening to me with a fresh install using the installer on Windows 11.

@aoeng
Copy link

aoeng commented Apr 21, 2023

how to fix it?

@coreybutler
Copy link
Owner

coreybutler commented Apr 21, 2023

This should be resolved by upgrading to v1.1.11. In v1.1.11, there is also a nvm debug command that will help identify any problems with reading your settings.txt. I will reopen if people are still running into this with v1.1.11.

@mikaelmello
Copy link

Still encountering this issue on 1.1.11:

C:\Program Files\nvm>nvm debug

ERROR open \settings.txt: The system cannot find the file specified.

C:\Program Files\nvm>nvm --version
1.1.11

@chill389cc
Copy link

chill389cc commented May 18, 2023

I'm also running into this issue with nvm version 1.1.11.
It was working for weeks but all of a sudden is throwing this error for me.
Sometimes it resolves itself but it often returns.

@qozle
Copy link

qozle commented May 24, 2023

Also encountering this issue with nvm version 1.1.11. I'm using InnoSetup.

While the terminal is still open (hasn't been restarted yet), I've checked my environment variable values. They are set correctly- as is my path, for both the user and system (admin). This isn't using the manual install. I can see the settings text document file in C:/users/MYUSER/AppData/Roaming/nvm directory.

I tried nvm debug and also got ERROR open \settings.txt: The System cannot find the file specified..

@lloydjatkinson
Copy link
Author

lloydjatkinson commented May 24, 2023

I have been suspicious of that path since I made this issue. I'm fairly sure it's because of the missing a dot, this is trivially easy to reproduce, it's trying to look on the root of C:.

image

image

It needs to be .\settings.txt here, and as NVM_HOM is not yet defined, the end result is the root of the disk:

var home = filepath.Clean(os.Getenv("NVM_HOME") + "\\settings.txt")

var home = filepath.Clean(os.Getenv("NVM_HOME") + "\\settings.txt")

@coreybutler
Copy link
Owner

The issue is NVM_HOME is not recognized at runtime. If it were just .\settings.txt, it would only work in one specific directory.

In PowerShell, run $env:NVM_HOME to see if the variable is set correctly. It should look like the following:

image

@mikaelmello
Copy link

On my case, the issue was not having reopened the terminal after installation so that NVM_HOME was set.

I had closed and opened new tabs but that does not trigger an environment reload on Windows I guess.

@coreybutler
Copy link
Owner

@mikaelmello it depends on which app is running powershell. The tabbed tools typically don't reload the environment until the app is reopened (VS Code is the same way). I wish there were a clearer way to determine this behavior, but every shell app is different.

@qozle
Copy link

qozle commented May 26, 2023

I'm still struggling with this- trying to install nvm with Inno Setup.
I'm on v1.1.11 and getting the ERROR open \settings.txt...error. Using windows 10.

I've stepped through the install script I made in debug mode, and it's not finding the settings.txt file, even though the correct env variables are set, and they are present on the PATH (for system and user). Are there any tricks for dealing with this, if you can't restart the terminal?

-EDIT- I'm discovering now that when I look at defined environmental variables using SET, I don't see NVM_HOME, NVM_SYMLINK or the correct locations appended to the path variable.

@mikaelmello
Copy link

A slight improvement on the ux might be what other Linux projects do after a install on the terminal: printing the necessary commands to set the variables for this session.

@qozle
Copy link

qozle commented May 30, 2023

Unfortunately that wouldn't be a solution for us...the installer needs to be pretty much hands off, for our very not tech-savvy users.

I couldn't get this to install successfully using Inno Setup to create an installer. It seems the issue boiled down to the environmental variables not being recognized. They were set correctly, but just not from the terminal's perspective. That is to say, I could find the environmental variables correctly set while clicking through windows settings, or viewing them in the registry, but when I used the SET command in the terminal that was doing the install...the environmental variables weren't set.

From that termainal, I could successfully call the nvm command without any passed arguments, however it failed with ERROR open \settings.txt: The system cannot find the file specified when using any nvm command (even debug).

@bitdeep
Copy link

bitdeep commented Aug 4, 2023

This error is because your current command line prompt does not have %NVM_HOME%, just close your command prompt and open it again and it should work.

@lloydjatkinson
Copy link
Author

Is this a serious reply or some AI generated reply? Please read original issue comment to understand this problem, it’s context, and usage with automation scripts and tools like winget.

@coreybutler
Copy link
Owner

Actually @lloydjatkinson, @bitdeep's comment isn't necessarily off-base. If NVM_HOME isn't defined, NVM4W won't be recognized.

I'd also like to point out that I do't maintain the winget package, or the scoop package. The official installer, which was written with InnoSetup, should setup the environment variables appropriately. Upon completion of install, restarting the terminal may be required because InnoSetup ometimes has an untraceable race condition where the terminal launches/reloads before the environment variables are created. It's an annoying InnoSetup problem I have not found a solution to.

@bitdeep
Copy link

bitdeep commented Aug 4, 2023

Is this a serious reply or some AI generated reply? Please read original issue comment to understand this problem, it’s context, and usage with automation scripts and tools like winget.

It's not ai generated ser, I just had this issue. So I decided to drop a come here to help people.

@Aikenwu
Copy link

Aikenwu commented Nov 4, 2023

image
image
for me , seem like use [edit the system environment variables] reset nvm_home path , then is correct.
image

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

No branches or pull requests