Summary
Sister bug to #112 (closed in 2.14.3). The JSON-import-attribute issue is fixed, but a second strict-ESM violation in dist/services/sqlite/sqlite-bootstrap.js keeps the plugin from loading on opencode ≥1.15 (Bun-based runtime).
Error
opencode log:
ERROR service=plugin path=opencode-mem
target=file:///…/opencode-mem@latest/node_modules/opencode-mem/dist/plugin.js
error=require is not defined in ES module scope, you can use import instead
in dist/services/sqlite/sqlite-bootstrap.js:4
const bunSqlite = require("bun:sqlite");
failed to load plugin
Root Cause
src/services/sqlite/sqlite-bootstrap.ts mixes a CommonJS require() call into an ESM module (parent package.json has "type": "module"):
let Database: typeof import("bun:sqlite").Database;
export function getDatabase(): typeof import("bun:sqlite").Database {
if (!Database) {
const bunSqlite = require("bun:sqlite") as typeof import("bun:sqlite");
Database = bunSqlite.Database;
}
return Database;
}
Under Bun's strict-ESM mode (used by opencode's embedded Bun runtime in 1.15.x), require is not available in ESM scope. The compiled dist/services/sqlite/sqlite-bootstrap.js carries the same require() call verbatim.
Fix
One-line change — replace require() with a top-level static import (which works fine because bun:sqlite is a Bun built-in):
import { Database as BunDatabase } from "bun:sqlite";
let Database: typeof BunDatabase;
export function getDatabase(): typeof BunDatabase {
if (!Database) Database = BunDatabase;
return Database;
}
I verified the workaround locally by overwriting the cached dist/services/sqlite/sqlite-bootstrap.js with the equivalent ESM-only version — plugin now loads cleanly on opencode 1.15.10 / Bun-v1.3.14 / macOS arm64.
Environment
- macOS 26.3 (Apple Silicon, arm64)
- opencode 1.15.10 (Homebrew
anomalyco/opencode, embeds bun-v1.3.14)
- opencode-mem 2.14.3 (latest), installed via opencode's plugin cache at
~/.cache/opencode/packages/opencode-mem@latest/
Related
Summary
Sister bug to #112 (closed in 2.14.3). The JSON-import-attribute issue is fixed, but a second strict-ESM violation in
dist/services/sqlite/sqlite-bootstrap.jskeeps the plugin from loading on opencode ≥1.15 (Bun-based runtime).Error
opencode log:
Root Cause
src/services/sqlite/sqlite-bootstrap.tsmixes a CommonJSrequire()call into an ESM module (parentpackage.jsonhas"type": "module"):Under Bun's strict-ESM mode (used by opencode's embedded Bun runtime in 1.15.x),
requireis not available in ESM scope. The compileddist/services/sqlite/sqlite-bootstrap.jscarries the samerequire()call verbatim.Fix
One-line change — replace
require()with a top-level static import (which works fine becausebun:sqliteis a Bun built-in):I verified the workaround locally by overwriting the cached
dist/services/sqlite/sqlite-bootstrap.jswith the equivalent ESM-only version — plugin now loads cleanly on opencode 1.15.10 / Bun-v1.3.14 / macOS arm64.Environment
anomalyco/opencode, embeds bun-v1.3.14)~/.cache/opencode/packages/opencode-mem@latest/Related
import pkg from "../package.json"needswith { type: "json" }(regression in 2.14.0) #112 (JSON-import-attribute), closed in v2.14.3 — this is the leftover sibling in the same area.