Skip to content

fix(opencode): convert bin script to ESM and fix local search path - #22770

Closed
r-siddiq wants to merge 2 commits into
anomalyco:devfrom
r-siddiq:fix/esm-binary-wrapper
Closed

r-siddiq wants to merge 2 commits into
anomalyco:devfrom
r-siddiq:fix/esm-binary-wrapper

Conversation

@r-siddiq

@r-siddiq r-siddiq commented Apr 16, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #22769

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR fixes two issues with the opencode binary wrapper:

  1. ReferenceError: require is not defined: Converted the wrapper script to ESM to support Node.js 25+ environments where "type": "module" is set in package.json.
  2. Local Binary Search: Updated the search logic in findBinary to also check the dist folder. This allows the wrapper to find locally built binaries in monorepo development environments, which was previously failing because the binaries weren't in node_modules.

How did you verify your code works?

  • Verified by running node packages/opencode/bin/opencode --version on Windows with Node.js v25.9.0.
  • Confirmed it correctly finds and executes the binary in the dist folder after a local build (bun run script/build.ts --single).
  • Smoke test in the build script also passed.

Screenshots / recordings

N/A (CLI change)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Apr 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@r-siddiq

Copy link
Copy Markdown
Author

I dug into the failing unit (windows) job.

The exposed assertion on this PR is:

The same Windows unit failure is also showing up on dev in run #34511:

This PR only changes packages/opencode/bin/opencode; plugin-loader.test.ts is unchanged relative to dev. I also ran bun test test/cli/tui/plugin-loader.test.ts --timeout 30000 locally from packages/opencode on Windows here, and that file passes.

Based on that, this looks unrelated to the wrapper change in this PR and more like a Windows-only CI/environment issue in the existing test.

@r-siddiq

Copy link
Copy Markdown
Author

Follow-up issue #22799 and fix PR #22800 are up. The follow-up PR now has green hosted CI, including unit (windows), so the Windows failure that was blocking this earlier PR is now tracked and fixed separately.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

@github-actions github-actions Bot closed this May 16, 2026
@r-siddiq
r-siddiq deleted the fix/esm-binary-wrapper branch May 17, 2026 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: ReferenceError: require is not defined in binary wrapper (Node.js 25+ / ESM)

1 participant