Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Fix rnw-dependencies.ps1 Node.js installation failures",
"packageName": "react-native-windows",
"email": "hmalothu@microsoft.com",
"dependentChangeType": "none"
}
16 changes: 15 additions & 1 deletion vnext/Scripts/rnw-dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ $requirements = @(
Name = 'Node.js (LTS, >= 22.0)';
Tags = @('appDev');
Valid = { CheckNode; }
Install = { WinGetInstall OpenJS.NodeJS.LTS "22.14.0" };
Install = { WinGetInstall OpenJS.NodeJS.LTS "22.22.0"};
HasVerboseOutput = $true;
},
@{
Expand Down Expand Up @@ -600,6 +600,9 @@ function WinGetInstall {
Write-Verbose "Executing `winget install `"$wingetPackage`"";
& winget install "$wingetPackage" --accept-source-agreements --accept-package-agreements
}

# Refresh PATH environment variable to pick up newly installed tools
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not needed I guess, cause the script is designed in a way to close the terminal after it finishes.
So refreshing path is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PATH refresh is needed because re-validation code calls Invoke-Command $req.Valid during the same script session.

For example, CheckNode uses Get-Command node which relies on the current $env:Path. Without refreshing PATH after winget install, the re-validation will fail even though Node.js was successfully installed.

The "close terminal" message at the end is for other applications that need the new PATH. But for the script's own validation to work, we need the refresh

}

function IsElevated {
Expand Down Expand Up @@ -685,6 +688,17 @@ foreach ($req in $filteredRequirements)
$LASTEXITCODE = 0;
$outputFromInstall = Invoke-Command $req.Install -ErrorAction Stop;

# Re-validate after install attempt - winget may return non-zero for "already installed"
$validAfterInstall = $false;
try {
$validAfterInstall = Invoke-Command $req.Valid;
} catch { }

if ($validAfterInstall) {
$Installed++;
continue; # go to the next item
}

if ($LASTEXITCODE -ne 0) {
throw "Last exit code was non-zero: $LASTEXITCODE - $outputFromInstall";
}
Expand Down
Loading