Skip to content

bin/opencode fails with 'require is not defined' in ESM packages #28343

Closed as not planned

Description

@qiushile

Problem

Running opencode --version on Node.js environments fails with:

ReferenceError: require is not defined in ES module scope

Root Cause

packages/opencode/bin/opencode is a JavaScript launcher using CommonJS require() syntax, but package.json declares "type": "module". Node.js resolves this file as ESM and require() is unavailable.

This affects all platforms (Linux, macOS, Windows) and any Node.js environment.

Reproduction

  1. Install opencode package from npm or clone repo
  2. Run node packages/opencode/bin/opencode --version (or any npm/pnpm/bun install that resolves the bin entry)
  3. Error: require is not defined in ES module scope

Expected Behavior

The launcher should execute successfully and spawn the platform-specific binary.

Fix

Rename bin/opencode → bin/opencode.cjs and update the bin field in package.json. The .cjs extension tells Node.js to treat the file as CommonJS regardless of package type. 1 file rename + 1 line change.

Activity

  1. github-actions commented on May 19, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of an existing issue. Please check:

  2. github-actions commented on Jul 19, 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