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

mklink is not reliable on windows 10 #266

Closed
6 of 17 tasks
fredericrous opened this issue May 4, 2017 · 4 comments
Closed
6 of 17 tasks

mklink is not reliable on windows 10 #266

fredericrous opened this issue May 4, 2017 · 4 comments

Comments

@fredericrous
Copy link
Contributor

fredericrous commented May 4, 2017

My Environment

  • Windows 7 or below (not truly supported due to EOL - see wiki for details)

  • Windows 8

  • Windows 8.1

  • Windows 10

  • Windows 10 IoT Core

  • Windows Server 2012

  • Windows Server 2012 R2

  • Windows Server 2016

  • My Windows installation is non-English.

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.
  • 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

nvm use <version> should create symlink at C:\Program Files\nodejs or at value provided in path argument in file settings.txt

Actual Behavior

The symlink is not always created, even if I run nvm use from an elevated shell.

Steps to reproduce the problem:

nvm install 6.9.1
nvm use 6.9.1

I'm prompted by elevate.cmd script, I answer yes, the symlink is not created

I don't know if it's related but I run nvm use from powershell.
Also It's kinda random, on some windows 10 I have the problem, on others I don't.
I believe a good workaround would be to test if symlink is created after running cmd.exe mklink. If symlink is not present, run powershell command new-item to create the link

@fredericrous fredericrous changed the title mdlink is not reliable on windows 10 mklink is not reliable on windows 10 May 4, 2017
@coreybutler
Copy link
Owner

Do you not actually see the symlink after running nvm use? Have you tried running the command in a standard shell instead of Powershell?

@youzaiyouzai666
Copy link

youzaiyouzai666 commented May 23, 2017

1.Please delete the installation node by window10 uninstall program

2.nvm install

3.modification Environment Variables window(reference)

Chinese interpretation:
1.window10 装nvm要先删掉电脑本身已经装的node,因nvm无法管理window10 已经装的nvm(报修改注册表失败)
2.装完nvm后使用nvm本身装 node
3.修改 NODE_PATH,为C:\Program Files\nodejs;因nvm在“C:\Program Files\nodejs”创建一个软连接,连接到“nvm root”(nvm root指向node实际目录)

@fredericrous
Copy link
Contributor Author

fredericrous commented May 24, 2017

@coreybutler : No I do not see the symlink after running nvm use.

Have you tried running the command in a standard shell instead of Powershell?

=> The whole point is to run it from powershell. Indeed I run a script that install lots of dependencies and configure the VM. Here is a subset of the script

$wc = New-Object System.Net.WebClient

# configure repositories
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

Get-Packageprovider -Name chocolatey
Set-PackageSource -Name Chocolatey -Trusted

Install-Package 7zip.install -ProviderName Chocolatey -RequiredVersion 16.02.0.20160811
$env:PATH+=";C:\Program Files\7-Zip"

$source = "https://github.com/coreybutler/nvm-windows/releases/download/1.1.3/nvm-setup.zip"
$archive = Join-Path $env:TEMP ($source.substring($source.lastindexOf('/') + 1))

$wc.DownloadFile($source, $archive)

echo "downloaded at: $archive"

7z x -aoa -y $archive "-o$env:TEMP"

#$uninstallScript = (Join-Path $PSScriptRoot uninstall_cmdline.ps1)
#&$uninstallScript -software "NVM for Windows*" | Out-Null

$nvmSetup = Join-Path $env:TEMP "nvm-setup.exe"
Start-Process $nvmSetup -ArgumentList @("/SILENT", "/SP-", "/SUPPRESSMSGBOXES") -Wait
ri $archive
ri $nvmSetup

$localNvmPath = Join-Path $env:APPDATA "nvm"
$defaultNodejsPath = "C:\Program Files\nodejs"
#Add-Path $localNvmPath
#Add-Env NVM_HOME $localNvmPath
ri $defaultNodejsPath -ErrorAction SilentlyContinue -Recurse -Force
nvm root $env:NVM_HOME
nvm install 4.5.0
nvm use 4.5.0
#create manually symlink if problem with nvm use, see https://github.com/coreybutler/nvm-windows/issues/266
#$nodePath = Join-Path $localNvmPath "v4.5.0"
#if ((-Not (Test-Path $nodePath) -or (-Not (Test-Path $defaultNodejsPath))))
#{
#    Start-Process powershell -Verb runAs -ArgumentList "-WindowStyle Hidden", "-Command `"&{ New-Item -Path `'$defaultNodejsPath`' -Value `'$nodePath`' -ItemType SymbolicLink }`"" -Wait -WindowStyle Hidden
#}

You should be able to put this script in a ps1 file and execute it as is. I commented Add-Env and Add-Path functions which respectively add variables to the env and folder location to the PATH. I also commented uninstall script call which basically uninstall nvm if any was installed before. I also commented the workaround I found: create the symlink manually.

@youzaiyouzai666 : I spawn a fresh VM on Windows 10 Enterprise 64bits, there is no previous node installed.

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
@coreybutler
Copy link
Owner

Closing due to age. This has not surfaced as a problem since this was filed. If it still impacts anyone, please open a new issue with a reference to this one.

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

3 participants