electric-sql / pglite

Lightweight WASM Postgres with real-time, reactive bindings.
https://pglite.dev
Apache License 2.0
8.06k stars 154 forks source link

Unable to load extensions in Web Worker #126

Closed gregnr closed 1 month ago

gregnr commented 1 month ago

The new extension system is amazing 🎉 but having an issue loading extensions in a Web Worker:

Works:

import { PGlite } from '@electric-sql/pglite'
import { vector } from '@electric-sql/pglite/vector'

const db = new PGlite(`idb://my-db`, {
  extensions: {
    vector,
  },
})

Fails:

import { PGliteWorker } from '@electric-sql/pglite/worker'
import { vector } from '@electric-sql/pglite/vector'

const db = new PGliteWorker(`idb://my-db`, {
  extensions: {
    vector,
  },
})

with error:

DOMException: Failed to execute 'postMessage' on 'Worker': async(s,n)=>({emscriptenOpts:n,bundlePath:/* asset import */ new __webpack_req...<omitted>...}) could not be cloned.

My best guess is something to do with being enable to serialize/wrap the vector module/function when sending to the Web Worker through comlink.

This is running in a Next.js application.


Edit: will likely be fixed by https://github.com/electric-sql/pglite/pull/120

samwillis commented 1 month ago

This is fixed in main with #120 merged. Will realise a new alpha later today.