pi-memory icon indicating copy to clipboard operation
pi-memory copied to clipboard

Startup failure: "No such built-in module: node:sqlite"

Open sirenkovladd opened this issue 5 months ago • 2 comments

❯ pi -v
0.79.3

❯ pi
Error: Failed to load extension "/Users/vlad/.pi/agent/npm/node_modules/@samfp/pi-memory/dist/index.js": Failed to load extension: ResolveMessage: No such built-in module: node:sqlite
❯ bun repl
Welcome to Bun v1.3.14
Type .copy [code] to copy to clipboard. .help for more info.

❯ import a from 'bun:sqlite'
[class Database]
❯ a
[class Database]
❯ import b from 'node:sqlite'
error: No such built-in module: node:sqlite
❯

I see that pi building using bun https://github.com/earendil-works/pi/blob/main/scripts/build-binaries.sh#L139

sirenkovladd avatar Jun 13 '26 22:06 sirenkovladd

Fixed in #26 (merged to master).

The root cause: node:sqlite is a Node ≥22 built-in that Bun doesn't implement — Bun has bun:sqlite instead. Both expose the same synchronous prepare/exec/get/all/run surface, so the fix is just a runtime-conditional import:

const isBun = typeof globalThis.Bun !== 'undefined';
const DatabaseSync = isBun
  ? require('bun:sqlite').Database
  : require('node:sqlite').DatabaseSync;

Will publish a patch release shortly.

samfoy avatar Jun 16 '26 19:06 samfoy

problem still exists, since you use esbuild src/index.ts --bundle --platform=node you have import { DatabaseSync } from "node:sqlite"; in https://github.com/samfoy/pi-memory/blob/master/dist/index.js#L8

sirenkovladd avatar Jun 17 '26 05:06 sirenkovladd