Home > OS >  How to resolve powershell errors when installing react-native-windows in windows 11
How to resolve powershell errors when installing react-native-windows in windows 11

Time:04-08

I got a new system running on windows 11 and I'm having issues running the shell script to set up react native windows environment.

Set-ExecutionPolicy Unrestricted -Scope Process -Force; iex (New-Object System.Net.WebClient).DownloadString('https://aka.ms/rnw-deps.ps1') Please I need help resolving this error.

The script can be found at enter image description here

CodePudding user response:

The script you link to is broken (as of this writing):

Line 98:

Write-Debug No Retail versions of Visual Studio found, trying pre-release...

This line causes a syntax error, due to missing quoting; the correct syntax is:

Write-Debug 'No Retail versions of Visual Studio found, trying pre-release...'

Line 130:

$p = Start-Process -PassThru -Wait  -FilePath $vsInstaller -ArgumentList ("modify --channelId $channelId --productId $productId $addWorkloads --quiet --includeRecommended" -split ' ')

The fact that this line fails indicates that at least one of the referenced variables - $channelId, $productId, $addWorkloads is unexpectedly $null.

As an aside:

  • That an error results from this is a manifestation of a Windows PowerShell bug (which has since been fixed in PowerShell (Core) 7 ) - passing an empty array or $null or an array that has at least one $null element to the -ArgumentList property of Start-Process unexpectedly causes an error.

  • There is a separate Start-Process bug - still present as of PowerShell Core 7.2.2 - the workaround for which makes it better to pass all arguments as a single string with embedded "..." quoting (as needed) to -ArgumentList (see this answer):

    $p = Start-Process -PassThru -Wait  -FilePath $vsInstaller -ArgumentList "modify --channelId $channelId --productId $productId $addWorkloads --quiet --includeRecommended"
    
  • Related