coreybutler / nvm-windows

A node.js version management utility for Windows. Ironically written in Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

exit status 1: Access is denied

CASPERg267 opened this issue · comments

Issue:
i get access is denied when i try to use specific version of node

How To Reproduce:
i installed 2 version node 14 and node 16
when trying to use node version 14 by typing nvm use 14.18.2 i get this error
same error happens when using v16

Expected Behavior:
It should use node version i choose to use

@CASPERg267 try to open the CMD as administrator

Ideally this would be addressed with a UAC dialog for those of who have local admin privileges but are not able to enable a Developer mode (likely due to running on an older version of Win10 or due to being locked out because of group policy restrictions).

Would you be willing to add the option to configure nvm to enable this alternative approach?

Even then, not everyone has administrative rights to the computer (some of us work with impossed restrictive policies) and as of testing it today with developer mode activated, this no longer works as intended (i.e. I have developer mode active, yet I get access denied when issuing an nvm use command).

Can confirm that even with developer mode enabled, the access denied error still happens. Windows 10, 20H2, build 19042.1645.

Can also confirm that I can create symbolic links manually from a non-administrator powershell session:
image

The second most common permission issue is trying to use a protected directory for storing Node installations. Windows requires administrative privileges to write to C:\Program Files. Many users want to install different versions of Node to this directory, but this forces NVM4W to create download (write) Node/npm to a protected directory. It's typically simpler to store Node installations in an alternative directory, such as C:\nvm4w.

Several people have complained about protected directories, and I'm sorry... but I'm not the person to talk to about that. Your best bet is to reach out to Microsoft, because it's an operating system requirement. Every program has to deal with this. Remember that NVM4W is basically an installer, so it needs installer-like permissions.

@coreybutler I found a solution for that as people can install both node and nvm in another disk (e.g. d:/) in order to avoid this. Perhaps consider adding this as a suggestion in your doc.

@terryjiang2020 has correctly cited that Windows protects some directories, even if you have developer mode enabled.

Per the suggestion, I've added the following change to the wiki:

image

curious that this has only become an issue lately...what has changed?

same issue here :(

commented

@coreybutler To reduce the number of people having this confusing problem, it might be a good idea to modify NVM4W to check whether it has administrative permissions proactively at launch, and display a meaningful warning. Or even link to the relevant README. I've found that it's possible to get into some quite odd states because some NVM4W commands work without admin permissions but some do not.

@coreybutler - may I suggest another potential addition to the wiki?

I've struggled for a few hours with this access denied error, enabling developer mode, using different folders to store my node installations. I was able to run the nvm commands from a normal command prompt or PowerShell terminal, but still got the access denied error in VS Code.

I finally found the issue was caused by the repository I was working on was cloned into my user's documents folder. I closed VSCode, moved the whole folder structure out of my documents folder and into a new folder, re-opened VSCode and blam, everything worked perfectly.

Please update the guide:

Checklist before installing nvm-windows

  • Developer mode on Windows: on
  • Uninstall all previous versions of nodejs and nvm.
  • Create the following folder structure:

-- c:\nvm4w
-- c:\nvm4w\nodejs
-- c:\nvm4w\nvm

  • Make them all write enabled (right click the folder, check properties, see that Read only is not marked at all)

Run the installer as an administrator.

  • When prompted, use your folders instead of the ones suggested by default in the installer.
  • Once finished, close any terminal, cmd or PowerShell window where you intend to use nvm, and
  • Open a new one.

Test everything is ok

  • Run nvm --version to check if it's installed correctly.
  • Run nvm root to verify that your settings have been applied correctly.

Run it

  • Run nvm install
  • When finished, run nvm use

running npm use <version> in a cmd opened with administrator privileges solved it for me

I couldn't get nvm-windows to work on my Windows 10 that's heavily locked down by my company's IT dept. I have local admin rights, but in a separate account. After running "nvm use " in an administrator prompt, I was unable to use the installed node from a non-admin prompt. Whenever I interacted with the symlink created, it just said access denied. When I looked at the symlink in explorer, it prompted me to grant myself access, but then that failed if I tried it.

I think admin rights are too restricted on my machine. I'm going to manually install multiple nodes and just switch my PATH each time.

I don't see why nvm needs to run as adminstrator anyway? I feel like it would be much more accessible to most users if it ran as a regular user.

You wrote in the docs that "Windows requires elevated administrative privileges to create symlinks", but that's not true.

On my Windows 10, I can create a symlink to a dir as a normal user with mklink /J link target. I'm pretty sure this has worked for several versions of windows, perhaps since they first added NTFS itself.

mklink /J

/J makes an NTFS junction, not symbolic link.

Also I think the admin rights are only for when you install into one of the "Program Files" folders, as those require special permissions. After I installed nvm to a regular folder it works just fine without admin privileges.

I'm locking this conversation because comments are starting to deviate from the subject. If you have suggestions or wish to discuss a feature, the discussions is the appropriate place to do it. I do not make a habit of reading through closed issues.