diff --git a/studio/setup.ps1 b/studio/setup.ps1 index 4cd19fdb03..0ac54d3866 100644 --- a/studio/setup.ps1 +++ b/studio/setup.ps1 @@ -919,11 +919,37 @@ if ($NeedFrontendBuild -and -not $IsPipInstall) { $UseBun = $null -ne (Get-Command bun -ErrorAction SilentlyContinue) + # bun's package cache can become corrupt -- packages get stored with only + # metadata but no actual content (bin/, lib/). When this happens bun install + # exits 0 but leaves binaries missing. We validate after install and clear + # the cache + retry once before falling back to npm. if ($UseBun) { Write-Host " Using bun for package install (faster)" -ForegroundColor DarkGray & bun install *> $null $bunExit = $LASTEXITCODE - if ($bunExit -ne 0) { + # On Windows, .bin/ entries can be tsc, tsc.cmd, or tsc.ps1 + $hasTsc = (Test-Path "node_modules\.bin\tsc") -or (Test-Path "node_modules\.bin\tsc.cmd") + $hasVite = (Test-Path "node_modules\.bin\vite") -or (Test-Path "node_modules\.bin\vite.cmd") + if ($bunExit -eq 0 -and $hasTsc -and $hasVite) { + # bun install succeeded and critical binaries are present + } elseif ($bunExit -eq 0) { + Write-Host " bun install exited 0 but critical binaries are missing, clearing cache and retrying..." -ForegroundColor Yellow + if (Test-Path "node_modules") { + Remove-Item "node_modules" -Recurse -Force -ErrorAction SilentlyContinue + } + & bun pm cache rm *> $null + & bun install *> $null + $bunExit = $LASTEXITCODE + $hasTsc = (Test-Path "node_modules\.bin\tsc") -or (Test-Path "node_modules\.bin\tsc.cmd") + $hasVite = (Test-Path "node_modules\.bin\vite") -or (Test-Path "node_modules\.bin\vite.cmd") + if ($bunExit -ne 0 -or -not $hasTsc -or -not $hasVite) { + Write-Host " bun retry failed, falling back to npm" -ForegroundColor Yellow + if (Test-Path "node_modules") { + Remove-Item "node_modules" -Recurse -Force -ErrorAction SilentlyContinue + } + $UseBun = $false + } + } else { Write-Host " [WARN] bun install failed (exit $bunExit), falling back to npm" -ForegroundColor Yellow if (Test-Path "node_modules") { Remove-Item "node_modules" -Recurse -Force -ErrorAction SilentlyContinue