Skip to content

Commit 596a0a2

Browse files
HariniMalothu17Harini Malothu
andauthored
Fix rnw-dependencies.ps1 Node.js installation failures (#15548)
* Fix rnw-dependencies.ps1 Node.js installation failures * Change files * Fix node.js version * update command --------- Co-authored-by: Harini Malothu <hmalothu@microsoft.com>
1 parent 206c4ee commit 596a0a2

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "none",
3+
"comment": "Fix rnw-dependencies.ps1 Node.js installation failures",
4+
"packageName": "react-native-windows",
5+
"email": "hmalothu@microsoft.com",
6+
"dependentChangeType": "none"
7+
}

vnext/Scripts/rnw-dependencies.ps1

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ $requirements = @(
469469
Name = 'Node.js (LTS, >= 22.0)';
470470
Tags = @('appDev');
471471
Valid = { CheckNode; }
472-
Install = { WinGetInstall OpenJS.NodeJS.LTS "22.14.0" };
472+
Install = { WinGetInstall OpenJS.NodeJS.22 "22.22.0"};
473473
HasVerboseOutput = $true;
474474
},
475475
@{
@@ -600,6 +600,9 @@ function WinGetInstall {
600600
Write-Verbose "Executing `winget install `"$wingetPackage`"";
601601
& winget install "$wingetPackage" --accept-source-agreements --accept-package-agreements
602602
}
603+
604+
# Refresh PATH environment variable to pick up newly installed tools
605+
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
603606
}
604607

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

691+
# Re-validate after install attempt - winget may return non-zero for "already installed"
692+
$validAfterInstall = $false;
693+
try {
694+
$validAfterInstall = Invoke-Command $req.Valid;
695+
} catch { }
696+
697+
if ($validAfterInstall) {
698+
$Installed++;
699+
continue; # go to the next item
700+
}
701+
688702
if ($LASTEXITCODE -ne 0) {
689703
throw "Last exit code was non-zero: $LASTEXITCODE - $outputFromInstall";
690704
}

0 commit comments

Comments
 (0)