coreybutler / nvm-windows

A node.js version management utility for Windows. Ironically written in Go.
MIT License
37.04k stars 3.3k forks source link

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

Open GerHobbelt opened 7 years ago

GerHobbelt commented 7 years ago

My Environment

I have already...

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

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:

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

GerHobbelt commented 7 years ago

Yes, I have tried to invoke nvm from git-bash, and hit the issue then.

however, I also tried running it from a cmd shell which itself was started from a git-bash shell and there the troubles were the same.

then ditto for powershell from git-bash to run nvm from inside that one: no go.

After that, running nvm from a cmd shell started straight from the Windows Start menu also produced this issue.

After that I got frustrated and went looking for the reason why those popups kept nagging me without ever giving me an option to accept and transition into administrator mode via the usual UAC process (popup to accet yes.no and click yes to execute command)

I don't know exactly what made it go away in the end; I fear I've somehow 'magically' twiddled some obscure security bit in the C:\Program Files\ directory tree while testing several ways to get that darn mklink command working (and deleting the manual attempts which succeeded). I have not explicitly edited the security settings of said directory along the way, but sometimes Windows throws me a curve ball that I cannot explain... and this is one of those occasions, unfortunately. :-((

I listed those powershell commands in case someone else runs into this trouble and travels a similar looking-for-ways-out path like me: the 'fun' bit here is that many websites', including many stackoverflow answers, did not deliver on my machine: I cobbled those powershell commands together after several failed copy-paste attempts from those google search results.

Met vriendelijke groeten / Best regards,

Ger Hobbelt


web: http://www.hobbelt.com/ http://www.hebbut.net/ mail: ger@hobbelt.com mobile: +31-6-11 120 978

On Fri, Jun 23, 2017 at 8:58 PM, Chris Pizzurro notifications@github.com wrote:

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

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/coreybutler/nvm-windows/issues/281#issuecomment-310746969, or mute the thread https://github.com/notifications/unsubscribe-auth/AAYkHgLUxY12Zy8h9YkuPMpYZdftkOazks5sHArngaJpZM4OBJeW .

coreybutler commented 7 years ago

@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 commented 7 years ago

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

ashnur commented 7 years ago

can confirm that reinstalling fixes the issue

rajsite commented 6 years ago

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 commented 5 years ago

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