Skip to content

fix: Enable Windows builds and fix bun+pnpm install on Windows#4273

Merged
rekram1-node merged 4 commits intoanomalyco:devfrom
Hona:fix/bun-windows
Nov 13, 2025
Merged

fix: Enable Windows builds and fix bun+pnpm install on Windows#4273
rekram1-node merged 4 commits intoanomalyco:devfrom
Hona:fix/bun-windows

Conversation

@Hona
Copy link
Copy Markdown
Member

@Hona Hona commented Nov 13, 2025

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

Fixes anomalyco#3363 - `bun install -g opencode-ai` now works on Windows
Copilot AI review requested due to automatic review settings November 13, 2025 02:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes critical Windows build and installation issues for OpenCode by ensuring platform identifier consistency and proper path handling across the build and postinstall scripts.

  • Unified platform identifier to use "win32" instead of "windows" throughout the codebase to match Node.js's process.platform
  • Fixed Windows path separator issues by normalizing backslashes to forward slashes in bundled paths
  • Added explicit bun support on Windows by copying the executable directly instead of relying on wrapper scripts

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/opencode/script/postinstall.mjs Updated platform detection to use "win32" consistently, added bun-specific binary installation logic for Windows that copies the .exe directly, and improved user agent detection with safe fallback
packages/opencode/script/build.ts Changed platform identifier from "windows" to "win32" in target definitions, normalized Windows path separators in the tree-sitter worker path, and simplified package.json OS field generation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Hona Hona changed the title fix: Enable Windows builds and fix bun install on Windows fix: Enable Windows builds and fix bun+pnpm install on Windows Nov 13, 2025
Comment thread packages/opencode/script/postinstall.mjs
@rekram1-node rekram1-node merged commit 43a8d1b into anomalyco:dev Nov 13, 2025
3 checks passed
xywsxp pushed a commit to xywsxp/opencode that referenced this pull request Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

windows version installed from pnpm does not work make bun install work on Windows

3 participants