Improve the error message when trying to use OPFS outside of a worker
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
I have a minimal-repro repo here that has the issue: https://github.com/TheAndrewJackson/opfs-ahp_bug_repro
https://pglite.dev/examples/opfs
It needs to be somewhere that allows the sync api, so in a web/service (shared?) worker.
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.
ahh, that makes sense @samwillis. Thanks for the clarification!