Skip to content

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

Closed as not planned

Description

@r-siddiq

Description

In Node.js v25 and later, when a package's package.json contains "type": "module", all files are treated as ES modules. The current binary wrapper script (packages/opencode/bin/opencode) uses CommonJS require statements, which leads to a ReferenceError: require is not defined.

Additionally, in development environments where platform-specific binaries are not yet installed in node_modules, the wrapper fails to find the locally built binary in the dist folder.

OpenCode version

1.4.6 (current dev)

Steps to reproduce

  1. Use Node.js v25.9.0 or later.
  2. Run opencode command from the monorepo root or after a local build.
  3. Observe the ReferenceError: require is not defined error.

Operating System

Windows 11 (Node.js v25.9.0)

Suggested Fix

  • Convert the binary wrapper script (packages/opencode/bin/opencode) to use ESM import statements.
  • Use fileURLToPath(import.meta.url) to correctly derive __filename and __dirname in an ESM context.
  • Update the findBinary function to also search in the dist directory to support local development in monorepo environments.

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 16, 2026
  2. r-siddiq commented on Apr 16, 2026

    @r-siddiq
    Author

    I've submitted a fix for this in PR #22770. The fix converts the binary wrapper to ESM to support Node.js 25+ and updates the search path to include the \dist\ folder for local development.

  3. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  4. github-actions commented on Jul 4, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions