-
Notifications
You must be signed in to change notification settings - Fork 49
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
[BUG] Any other Node installation takes precedence over the NVM Desktop version (user PATH always comes after system PATH on Windows) #131
Comments
Tested Workaround / Proof of concept:
|
On Windows platforms, use the
Here is the relevant code for envpath: pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let env = hklm.open_subkey_with_flags(
r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment",
KEY_READ | KEY_WRITE,
)?;
let env_path: String = env.get_value("PATH").unwrap_or_default();
// if not exist then add
if config.query == "add" && !env_path.split(";").any(|p| p == config.path) {
let new_env_path = format!("{};{}", env_path, config.path);
env.set_value("PATH", &new_env_path)?;
}
// remove from path
if config.query == "remove" {
let new_env_path = env_path
.split(";")
.filter(|p| *p != config.path)
.collect::<Vec<&str>>()
.join(";");
env.set_value("PATH", &new_env_path)?;
}
Ok(())
} It is designed to always be added to the end of the system environment variables, not the beginning. I'm not sure if raising its priority in the environment variables will make some users feel unfriendly. Perhaps this can be discussed first, and I will deal with this issue after confirming that it is acceptable. |
@1111mp raising the priority by default is not needed. The important part is allowing user to do so if he has multiple Node installs, e.g. Node installed already from the official Node installer, or by Volta. The issue is, that it is not possible when shims are in user PATH, because Node/Volta are in system PATH and system PATH always precedes user PATH on Windows. Moving the shims to "%ProgramFiles%\NVM Deskop\bin" allows the user to put them ahead of previous Node installs in system PATH. |
I think you just need to make sure that "%UserProfile%.nvmd\bin" has a higher priority than "%ProgramFiles%\Volta" in the system environment variable PATH (that is, it is located in the front). |
Ah, you're correct, Many thanks for your help and for a great tool🔥 |
Hi @1111mp I tested the There's issue on Windows desktops with multiple users: Only the user who installed NVM Desktop can use it, while others have an inaccessible path in system PATH. It's reproducible on any Windows station by creating second account and login with it. I just did it on my too and the path is inaccessible. The multiple users Windows desktop is common case with desktops/virtuals in organizations, e.g. for developers in customer organization, or when connecting via VPN there. I also tried working around by adding I didn't see any other software using user folder in system PATH so far and I'm not aware of any way to make it work. The common solution is the one suggested in description above: Use WDYT? |
I think this is expected behavior as it helps maintain privacy as one of the accounts. If an account has administrator privileges, then the account can access files in the
Through investigation, it was found that the default location of Volta's shim directory on Windows is
However, Volta does provide the function of modifying the shim directory. Perhaps we should also add the same functionality to allow users to decide which directory the shims are stored in. |
Yes, Volta uses Putting the base node/npm/npx/yarn/pnpm shims in system PATH allows to prioritize them before default Node installation in PATH. That's not possible with base shims in user PATH as Windows always put system PATH before user PATH. On contrary, putting global npm packages shims in user PATH allows each user to have their own set of global packages installed and with cli runnable from PATH. It's quite common setup and NVMD could use it too IMO. WDYT? |
OK, I will implement this feature in the next version. (It may take a while...) 🌹 |
Describe the bug
When installing on Windows with Node already installed (globally, or using Volta), there's no way to prioritize NVM Desktop, because the shims are placed in
%UserProfile%\.nvmd\bin
and userPATH
always comes after systemPATH
on Windows.To Reproduce
Steps to reproduce the behavior:
where node
-> It still points to the original installation of NodeExpected behavior
User should be able to prioritize NVM Desktop in PATH.
Possible solution could be putting shims to system PATH
%ProgramFiles%\NVM Deskop\bin
instead, similarly to how Volta puts them to to%ProgramFiles%\Volta
. It seems like a good idea anyway, as there's no need for each user to have their own copy of the shims.Desktop:
The text was updated successfully, but these errors were encountered: