[PR #6044] fix: convert bin/opencode to ES module syntax and support local dev builds #11711

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

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

State: closed
Merged: No


This commit addresses two issues with the bin/opencode wrapper script:

  1. ES Module Compatibility: Converts CommonJS require() syntax to ES
    module imports. The package.json specifies "type": "module", which
    causes Node.js to treat .js files as ES modules. While Bun (the
    project's primary runtime) allows require() in ES modules, Node.js
    strictly enforces ES module syntax, causing failures for developers
    using Node.js.

  2. Local Development Support: Adds check for binaries in dist/ folder
    before looking in node_modules/. When developers build locally with
    'bun run build' and use npm link for testing, the compiled binaries
    are placed in dist/, but the wrapper only searched node_modules/,
    causing it to fail.

These changes improve the developer experience for contributors who:

  • Use Node.js instead of Bun for running the wrapper
  • Test local builds via npm link or similar methods

The changes are backward compatible - production packages continue to
work as the wrapper still checks node_modules/ as a fallback.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6044 **State:** closed **Merged:** No --- This commit addresses two issues with the bin/opencode wrapper script: 1. **ES Module Compatibility**: Converts CommonJS require() syntax to ES module imports. The package.json specifies "type": "module", which causes Node.js to treat .js files as ES modules. While Bun (the project's primary runtime) allows require() in ES modules, Node.js strictly enforces ES module syntax, causing failures for developers using Node.js. 2. **Local Development Support**: Adds check for binaries in dist/ folder before looking in node_modules/. When developers build locally with 'bun run build' and use npm link for testing, the compiled binaries are placed in dist/, but the wrapper only searched node_modules/, causing it to fail. These changes improve the developer experience for contributors who: - Use Node.js instead of Bun for running the wrapper - Test local builds via npm link or similar methods The changes are backward compatible - production packages continue to work as the wrapper still checks node_modules/ as a fallback.
yindo added the pull-request label 2026-02-16 18:16:39 -05:00
yindo closed this issue 2026-02-16 18:16:39 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11711