GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bin/opencode fails with 'require is not defined' in ESM packages · Issue #28343 · anomalyco/opencode

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

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
bin/opencode fails with 'require is not defined' in ESM packages#28343
Copy link
Assignees
rekram1-node

Description

@qiushile
qiushile
opened on May 19, 2026
Issue body actions

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
    assigned
    rekram1-node
    on May 19, 2026
  2. github-actions commented on May 19, 2026

    @github-actions
    github-actionsBot
    on May 19, 2026 – with GitHub Actions
    Contributor
    More actions

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

    • fix: ReferenceError: require is not defined in binary wrapper (Node.js 25+ / ESM) #22769: Same error (ReferenceError: require is not defined), same file (packages/opencode/bin/opencode), same root cause ("type": "module" + CommonJS require), and same proposed fix direction (rename to .cjs).
  3. github-actions commented on Jul 19, 2026

    @github-actions
    github-actionsBot
    on Jul 19, 2026 – with GitHub Actions
    Contributor
    More actions

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

  4. github-actions
    closed this as not plannedon Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @rekram1-node
    rekram1-node

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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.