pglite icon indicating copy to clipboard operation
pglite copied to clipboard

[Bug] Bun bundle not work with PgLite

Open esciullo opened this issue 1 year ago • 2 comments

What versions are running ?

  • Bun: 1.1.33
  • PgLite: 0.2.12

What steps can reproduce the bug ?

Use the following index.ts and package.json files and run

bun build --compile --sourcemap ./index.ts --outfile executable && ./executable

index.ts

import { PGlite } from "@electric-sql/pglite";

const db = new PGlite();
await db.waitReady;
const result = await db.query("select 'Hello world' as message;");
console.log(result);
await db.close();

package.json

{
  "name": "pglite-bundle",
  "private": true,
  "module": "index.ts",
  "type": "module",
  "dependencies": {
    "@electric-sql/pglite": "0.2.12"
  }
}

What is the expected behavior ?

The process runs successfully.

What do you see instead ?

The process fails with error

ENOENT: No such file or directory
   errno: -2
 syscall: "open"
   path: "/$bunfs/root/postgres.data"

esciullo avatar Nov 06 '24 11:11 esciullo

/$bunfs/root/postgres.data is a bun generated path and it is wrong. Just dont use compile until they fix packager ( afaik there are open issues already https://github.com/oven-sh/bun/issues?q=is%3Aissue%20%2F%24bunfs%2Froot )

pmp-p avatar Nov 06 '24 16:11 pmp-p

I did this workaround (it should work for both esbuild and bun)

divyenduz avatar Oct 11 '25 15:10 divyenduz