You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: ReferenceError: require is not defined in binary wrapper (Node.js 25+ / ESM) #22769
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
Use Node.js v25.9.0 or later.
Run opencode command from the monorepo root or after a local build.
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.
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.
Activity
r-siddiq commentedon Apr 16, 2026
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.
github-actions commentedon Jul 4, 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.