@@ -1060,6 +1060,84 @@ function Test-NpmConfigRawKey {
10601060 return $false
10611061}
10621062
1063+ function Add-NpmCacheCandidate {
1064+ param (
1065+ [System.Collections.Generic.List [string ]]$Candidates ,
1066+ [object ]$Path
1067+ )
1068+ foreach ($rawPath in @ ($Path )) {
1069+ $trimmed = " $rawPath " .Trim()
1070+ if (-not [string ]::IsNullOrWhiteSpace($trimmed ) -and -not $Candidates.Contains ($trimmed )) {
1071+ $Candidates.Add ($trimmed )
1072+ }
1073+ }
1074+ }
1075+
1076+ function Get-NpmDebugLogRootCandidates {
1077+ $candidates = New-Object System.Collections.Generic.List[string ]
1078+ Add-NpmCacheCandidate - Candidates $candidates - Path $env: NPM_CONFIG_CACHE
1079+
1080+ $detectedCache = (Invoke-NpmCommand - Arguments @ (" config" , " get" , " cache" ) 2> $null )
1081+ if ($LASTEXITCODE -eq 0 ) {
1082+ Add-NpmCacheCandidate - Candidates $candidates - Path $detectedCache
1083+ }
1084+
1085+ if ($env: LOCALAPPDATA ) {
1086+ Add-NpmCacheCandidate - Candidates $candidates - Path (Join-Path $env: LOCALAPPDATA " npm-cache" )
1087+ }
1088+ if ($env: APPDATA ) {
1089+ Add-NpmCacheCandidate - Candidates $candidates - Path (Join-Path $env: APPDATA " npm-cache" )
1090+ }
1091+ if ($env: USERPROFILE ) {
1092+ Add-NpmCacheCandidate - Candidates $candidates - Path (Join-Path $env: USERPROFILE " AppData\Local\npm-cache" )
1093+ }
1094+
1095+ return $candidates
1096+ }
1097+
1098+ function Get-LatestNpmDebugLogPath {
1099+ foreach ($cacheDir in (Get-NpmDebugLogRootCandidates )) {
1100+ $logDir = Join-Path $cacheDir " _logs"
1101+ if (-not (Test-Path - LiteralPath $logDir - PathType Container)) {
1102+ continue
1103+ }
1104+ $latestLog = Get-ChildItem - LiteralPath $logDir - Filter " *-debug-*.log" - File - ErrorAction SilentlyContinue |
1105+ Sort-Object LastWriteTimeUtc - Descending |
1106+ Select-Object - First 1
1107+ if ($latestLog ) {
1108+ return $latestLog.FullName
1109+ }
1110+ }
1111+ return $null
1112+ }
1113+
1114+ function Write-NpmInstallFailureDetails {
1115+ param ([object []]$Output )
1116+ $printedOutput = $false
1117+ foreach ($line in @ ($Output )) {
1118+ if ($null -eq $line ) {
1119+ continue
1120+ }
1121+ $text = " $line "
1122+ if ([string ]::IsNullOrWhiteSpace($text )) {
1123+ continue
1124+ }
1125+ Write-Host $text
1126+ $printedOutput = $true
1127+ }
1128+
1129+ $latestLog = Get-LatestNpmDebugLogPath
1130+ if ($latestLog ) {
1131+ Write-Host " Latest npm debug log ($latestLog ):" - ForegroundColor Yellow
1132+ Get-Content - LiteralPath $latestLog - Tail 120 - ErrorAction SilentlyContinue | ForEach-Object { Write-Host $_ }
1133+ return
1134+ }
1135+
1136+ if (-not $printedOutput ) {
1137+ Write-Host " npm produced no console output and no npm debug log was found." - ForegroundColor Yellow
1138+ }
1139+ }
1140+
10631141function Install-OpenClaw {
10641142 if ([string ]::IsNullOrWhiteSpace($Tag )) {
10651143 $Tag = " latest"
@@ -1119,7 +1197,7 @@ function Install-OpenClaw {
11191197 Write-Host " Re-run with verbose output to see the full error:" - ForegroundColor Yellow
11201198 Write-Host ' powershell -c "irm https://openclaw.ai/install.ps1 | iex"' - ForegroundColor Cyan
11211199 }
1122- $npmOutput | ForEach-Object { Write-Host $_ }
1200+ Write-NpmInstallFailureDetails - Output $npmOutput
11231201 return $false
11241202 }
11251203 } finally {
0 commit comments