Skip to content

TypeError: n.OpfsSAHPoolDb is not a constructor #79

@germanescobar

Description

@germanescobar

Hi, we are getting this error intermittently and we are having a really hard time recreating it and diagnosing what's happening. Does anyone here have an idea what's going on or have a suggestion of how we can debug it.

When the error occurs it prevents our app from initializing.

  • This is being called inside a Web Worker.
  • We use the Web Locks API to ensure that only an instance of this Web Worker exists.
import sqlite3InitModule from "@sqlite.org/sqlite-wasm";

// The sqlite3 wasm module needs to be initialized by the browser before
// it can be used. This must only be done once. We eagerly start this
// initialization process when this module is imported.
const modulePromise = sqlite3InitModule({
  print: console.log,
  printErr: console.error,
});
export async function createPersistedClientDatabaseAdapter(props: {
  logger: Logger;
  /** Resets the database on init, clearing all existing data. */
  clearOnInit?: boolean;
}) {
  const sqlite3 = await modulePromise;
  const poolUtil = await sqlite3.installOpfsSAHPoolVfs({
    clearOnInit: props.clearOnInit,
    directory: "/sqlite3",
  });
  props.logger.info({ poolUtil });
  const sqliteDB = new poolUtil.OpfsSAHPoolDb(`/comms.db`); // intermittent error
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions