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

nvm-windows not working on Windows 10/64/UAC: popup message but no symlink gets created #281

Open
6 of 9 tasks
GerHobbelt opened this issue Jun 21, 2017 · 9 comments
Open
6 of 9 tasks

Comments

@GerHobbelt
Copy link

My Environment

  • Windows 10/64-bit

I have already...

  • read the README to be aware of npm gotchas & antivirus issues.
  • reviewed the wiki to make sure my issue hasn't already been resolved.
  • verified I'm using an account with administrative privileges.

    NOTE: the account is an administrator but UAC is still ENABLED INTENTIONALLY.

  • searched the issues (open and closed) to make sure this isn't a duplicate.
  • made sure this isn't a question about how to use NVM for Windows, since gitter is used for questions and comments.

My issue is related to (check only those which apply):

  • settings.txt
  • proxy support
  • 32 or 64 bit support

Expected Behavior

UAC should pop up with a dialog to allow me to accept the changes (symlink creation) after having invoked nvm use x.y.z

Actual Behavior

nvm use x.y.z shows this dialog box twice in a row and doesn't create/update the symlink necessary to make node+npm work.

Steps to reproduce the problem:

  • Have UAC active.
  • remove any previous node installs.
  • install latest nvm-windows (using downloaded installer: nvm version = 1.1.5).
  • nvm install 8
  • nvm install 7
  • nvm on
  • nvm use 8
    --> pops up dialog as shown in the screenshot. No working node.

2017-06-21 1

Hack / solution path

Failure Diagnosis

Using SysInternals ProcExp it turns out that this command is failing:

wscript   //nologo "C:\Users\Ger\AppData\Roaming\nvm\elevate.vbs" cmd /C mklink /D "C:\Program Files\nodejs" C:\Users\Ger\AppData\Roaming\nvm\v8.0.0

Problem solution (experimental)

As elevate.vbs doesn't deliver on my platform as is (when using cmd to execute mklink), this command line however DOES work as expected/desired (popping up a UAC accept dialog):

powershell -Command "& { Start-Process cmd \"/C mklink /D C:\Program Files\nodejs C:\Users\Ger\AppData\Roaming\nvm\v8.0.0ing\nvm\v8.0.0 -Verb runas\" }"

WARNING

The quotes' escaping in there are critical: MS docs found on line said passing double quotes in a Powershell string should be done by duplication (""), but it turns out that did not work as-is: you'll need to backslash-escape them additionally as shown in the command lines below!

These two command lines (to nuke any existing symlink and then re-establish it) work on my platform:

powershell -Command "& { Start-Process cmd -Verb runas -ArgumentList \"/C rmdir \"\"C:\Program Files\nodejs\"\" \" }"

powershell -Command "& { Start-Process cmd -Verb runas -ArgumentList \"/C mklink /D \"\"C:\Program Files\nodejs\"\" C:\Users\Ger\AppData\Roaming\nvm\v8.0.0ing\nvm\v8.0.0\" }"

References for the above command lines

In more or less reverse order of having visited these (i.e. first entry was visited last):

Possibly related issues

@GerHobbelt
Copy link
Author

Post Scriptum

After re-installing nvm-windows (WITHOUT uninstalling it first!), the nvm use x.y.z commands do deliver as expected. No more error dialog from elevate.vbs and no need to go through powershell...

🤐 Though this may sound good, I don't like this 'magic disappearance' of the problem as it means this can happen again on any other box or when I wipe and re-install Windows on this box at some point (happens about once a year for me; call it "Annual Spring Cleaning After Major Screw-Up" ;-) ).

@wpwood
Copy link

wpwood commented Jun 22, 2017

I see this issue as well, and tried installing nvm-windows twice (without uninstalling it between installs), and it does not solve the issue for me. I have not tried your powershell scripts, but I suspect something in there actually solved the issue for you, not the re-installing. Could be wrong, though, so this is just a FYI.

@pizzurro
Copy link

I have seen this error when attempting to run from Git Bash. Works fine when run from cmd.exe.

@GerHobbelt
Copy link
Author

GerHobbelt commented Jun 23, 2017 via email

@coreybutler
Copy link
Owner

@GerHobbelt - first off, I'm sorry you've had such troubles with this. Unfortunately, many of the third party shells do not respect standard commands. Cygwin and git-bash are particularly bad about this. Sadly, I'm not sure why you weren't getting the UAC prompt. The OS determines when to display the prompt, so this is definitely perplexing. I haven't been able to replicate the issue.

Thank you very much for posting the resources and your research. If I can find some time, I will try to curate all of the different experiences users have posted and try to make a troubleshooting guide. Unfortunately, I've got 4 client projects and a product release... so it may be awhile before I can do this.

I'm going to keep this thread open for comments. If anyone tracks down an issue/work around for a particular shell, I will add it to the wiki until a formal guide can be made.

@ashnur
Copy link

ashnur commented Jul 12, 2017

I am having this issue from cmd and Powershell too, without using Cmder (which is my default way to use terminals on windows)

@ashnur
Copy link

ashnur commented Jul 12, 2017

can confirm that reinstalling fixes the issue

CodeBlueDev added a commit to CodeBlueDev/nvm-windows that referenced this issue Jul 13, 2017
The Go version used for the repository development could not be found
so the latest installation available was used. In doing so, some compile
time errors appeared with regards to filepath and the Unzip function
that had to be corrected.

The Go exec module wraps the os.StartProcess functionality. The initial
argument escaping appears to be correct, however, during the pipe
writing when actually starting the process the command is escaped again
in quotations making the command invalid. This makes the command fail
and no symlink is created.

This was verified by printing the resulting argument string by utilizing
the same logic that makes the command line argument and escapes it. As
this appears to be a Go library issue, a different tactic was attempted.
In case of this failure, a backup mechanism has been put in place to
use the os module to create the symlink directly.

After much deliberation it was decided this backup mechanism should only
be attempted when the initial attempt fails. The reasoning behind this
is because the initial command request attempts to elevate the command
which would give access to create the symbolic link in "Program Files",
which is otherwise a protected folder. The os call could fail here due
to insufficient permissions.

Potentially fixes: coreybutler#281, coreybutler#266, coreybutler#30
@rajsite
Copy link

rajsite commented Nov 30, 2017

I'm also seeing UAC prompts in Windows 10 64-bit Fall Creators Update (1709) when switching between node versions with nvm.

During install nvm-windows found two versions of node, v4.1.1 and v6.10.3.

Tried installing a second time (without uninstalling first) and it found just v6.10.3 and gave an additional prompt (I think it was about deleting node_modules) that did not happen the first time.

Uninstalled nvm which removed all my node versions. Installed nvm again which did not detect any node versions. nvm installed an 8 and 6 version. Still required two UAC prompts to switch versions.

@jaeseok-park
Copy link

I met this issue today. It worked well 3 month ago, but suddenly nvm use makes two error popup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants