bin/opencode fails with 'require is not defined' in ESM packages #28343
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Description
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
- Install opencode package from npm or clone repo
- Run
node packages/opencode/bin/opencode --version(or any npm/pnpm/bun install that resolves the bin entry) - 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
github-actions commentedon May 19, 2026
This issue might be a duplicate of an existing issue. Please check:
ReferenceError: require is not defined), same file (packages/opencode/bin/opencode), same root cause ("type": "module"+ CommonJSrequire), and same proposed fix direction (rename to.cjs).github-actions commentedon Jul 19, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.