pglite icon indicating copy to clipboard operation
pglite copied to clipboard

Improve the error message when trying to use OPFS outside of a worker

Open TheAndrewJackson opened this issue 1 year ago • 3 comments

Description

I'm running into an issue when trying to create a new database using the OPFS AHP file system. This snippet

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

const client = await PGlite.create({
  dataDir: "opfs-ahp://electric.db",
  relaxedDurability: true,
});

is producing this error

image

I have a minimal-repro repo here that has the issue: https://github.com/TheAndrewJackson/opfs-ahp_bug_repro

TheAndrewJackson avatar Aug 14 '24 20:08 TheAndrewJackson

https://pglite.dev/examples/opfs

It needs to be somewhere that allows the sync api, so in a web/service (shared?) worker.

AntonOfTheWoods avatar Aug 15 '24 03:08 AntonOfTheWoods

Thanks for the report @TheAndrewJackson

The OPFS AHP VFS only works in a dedicated web worker as it requires the sync access handle API which is not available on the main thread, in shared workers, or in service workers.

We should improve the error message on this.

samwillis avatar Aug 15 '24 11:08 samwillis

ahh, that makes sense @samwillis. Thanks for the clarification!

TheAndrewJackson avatar Aug 15 '24 11:08 TheAndrewJackson