[PR #4273] fix: Enable Windows builds and fix bun+pnpm install on Windows #10926

Closed
opened 2026-02-16 18:15:41 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/4273

State: closed
Merged: Yes


Fixes #3363 - bun install -g opencode-ai now works on Windows
Fixes #4195 - pnpm install -g opencode-ai now works on Windows

Problem

OpenCode could not be built or installed on Windows using bun due to three critical issues:

  1. Build script platform mismatch: The build script used "windows" as the platform identifier, but process.platform returns "win32" on Windows. This caused:

    • The --single flag to fail (built wrong platform or nothing at all)
    • Package names like opencode-windows-x64 that didn't match the expected opencode-win32-x64
  2. Windows path separator bug: The build script used path.relative() which returns backslashes on Windows (\), but the bundled code expected forward slashes (/). This
    caused syntax errors and made all Windows builds fail.

  3. Bun install failure: The postinstall script skipped all processing when detecting bun on Windows, causing bun to generate a default #!/bin/sh wrapper script that failed
    with:
    error: interpreter executable "/bin/sh" not found in %PATH%

Solution

1. Platform naming consistency

  • Changed platform identifier from "windows" to "win32" in:
    • build.ts: Target definitions and package.json generation
    • postinstall.mjs: Platform detection logic
  • This ensures consistency with Node.js's process.platform value

Warning

I'm not sure how this would interact with old installs -> upgrade paths

2. Path separator normalization

  • Added .replace(/\\/g, "/") to normalize Windows backslashes to forward slashes in bundled paths
  • Fixes the OTUI_TREE_SITTER_WORKER_PATH define that was causing build failures

3. Bun support on Windows

  • Added explicit bun detection and handling in postinstall.mjs
  • For bun on Windows: copies the .exe directly to the bin directory (bun doesn't need wrapper scripts)
  • For npm on Windows: continues to use npm rebuild to regenerate CMD/PS1 wrappers
  • For other package managers on Windows: gracefully skips with a clear message

Testing

Verified the following scenarios work correctly:

  • bun run script/build.ts --single on Windows (now builds opencode-win32-x64)
  • Full build on Windows without errors
  • bun install -g opencode-ai on Windows (no more /bin/sh error)
  • npm install -g opencode-ai on Windows (CMD wrappers still generated correctly)
  • Postinstall script correctly detects and handles npm vs bun on Windows
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4273 **State:** closed **Merged:** Yes --- Fixes #3363 - `bun install -g opencode-ai` now works on Windows Fixes #4195 - `pnpm install -g opencode-ai` now works on Windows ### Problem OpenCode could not be built or installed on Windows using bun due to three critical issues: 1. **Build script platform mismatch**: The build script used `"windows"` as the platform identifier, but `process.platform` returns `"win32"` on Windows. This caused: - The `--single` flag to fail (built wrong platform or nothing at all) - Package names like `opencode-windows-x64` that didn't match the expected `opencode-win32-x64` 2. **Windows path separator bug**: The build script used `path.relative()` which returns backslashes on Windows (`\`), but the bundled code expected forward slashes (`/`). This caused syntax errors and made all Windows builds fail. 3. **Bun install failure**: The postinstall script skipped all processing when detecting bun on Windows, causing bun to generate a default `#!/bin/sh` wrapper script that failed with: error: interpreter executable "/bin/sh" not found in %PATH% ### Solution #### 1. Platform naming consistency - Changed platform identifier from `"windows"` to `"win32"` in: - `build.ts`: Target definitions and package.json generation - `postinstall.mjs`: Platform detection logic - This ensures consistency with Node.js's `process.platform` value > [!WARNING] > I'm not sure how this would interact with old installs -> upgrade paths #### 2. Path separator normalization - Added `.replace(/\\/g, "/")` to normalize Windows backslashes to forward slashes in bundled paths - Fixes the `OTUI_TREE_SITTER_WORKER_PATH` define that was causing build failures #### 3. Bun support on Windows - Added explicit bun detection and handling in `postinstall.mjs` - For bun on Windows: copies the `.exe` directly to the bin directory (bun doesn't need wrapper scripts) - For npm on Windows: continues to use `npm rebuild` to regenerate CMD/PS1 wrappers - For other package managers on Windows: gracefully skips with a clear message ### Testing Verified the following scenarios work correctly: - ✅ `bun run script/build.ts --single` on Windows (now builds `opencode-win32-x64`) - ✅ Full build on Windows without errors - ✅ `bun install -g opencode-ai` on Windows (no more `/bin/sh` error) - ✅ `npm install -g opencode-ai` on Windows (CMD wrappers still generated correctly) - ✅ Postinstall script correctly detects and handles npm vs bun on Windows
yindo added the pull-request label 2026-02-16 18:15:41 -05:00
yindo closed this issue 2026-02-16 18:15:41 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10926