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.
Problem
Running
opencode --versionon Node.js environments fails with:Root Cause
packages/opencode/bin/opencodeis a JavaScript launcher using CommonJSrequire()syntax, butpackage.jsondeclares"type": "module". Node.js resolves this file as ESM andrequire()is unavailable.This affects all platforms (Linux, macOS, Windows) and any Node.js environment.
Reproduction
node packages/opencode/bin/opencode --version(or any npm/pnpm/bun install that resolves the bin entry)require is not defined in ES module scopeExpected Behavior
The launcher should execute successfully and spawn the platform-specific binary.
Fix
Rename
bin/opencode→bin/opencode.cjsand update thebinfield inpackage.json. The.cjsextension tells Node.js to treat the file as CommonJS regardless of package type. 1 file rename + 1 line change.