Skip to content

Question: How can I use this package in a library? #19

@DallasHoff

Description

@DallasHoff

I have been trying to figure out how I can use this package as a dependency in a library I am building. The web worker from @sqlite.org/sqlite-wasm creates a second web worker using sqlite3-opfs-async-proxy.js and this is presenting problems when I attempt to bundle my library. I have tried to use Vite, Tsup, Parcel, and Rollup to bundle my library, but I encounter similar issues in each that all stem from the way that this package is structured with that inner worker:

  1. When the first worker attempts to construct the inner worker in the app, it tries to fetch sqlite3-opfs-async-proxy.js, but this 404s since it would require the app consuming the library to serve sqlite3-opfs-async-proxy.js themselves.
  2. So, if I try to inline the inner worker in the library bundle by converting it to a data URL (new Worker("data:application/javascript;base64,...")), OPFS is not available because the origin in that context is the data URL that my library's worker is inlined as, not the app's origin, and obviously a data URL cannot have the required HTTP headers.

As it stands, I can use @sqlite.org/sqlite-wasm as the direct dependency of an app, but I have been struggling to use it as a dependency of a library. I would really appreciate some guidance.

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