sqlite / sqlite-wasm

SQLite Wasm conveniently wrapped as an ES Module.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sqlite3 result code 1: no such vfs: opfs

bearjaws opened this issue · comments

Hey all,

I recently migrated my usage of sqlite-wasm from a localhost project to a https hosted domain and it no longer seems to be working. This is using a web worker, Running SQLite3 version 3.46.0

I tried in both Chrome + Firefox and both are broken the same way.

Here is some sample code where I initialize the connection

 log('Loading and initializing SQLite3 module...');

    promiser = await new Promise((resolve) => {
      // @ts-expect-error poor TS support from SQLITE3
      const _promiser = sqliteWasm.sqlite3Worker1Promiser({
        onready: () => resolve(_promiser),
      });
    });

    log('Done initializing.');

    const configResponse = await promiser('config-get', {});
    log('Running SQLite3 version', configResponse.result.version.libVersion);
    const openResponse = await promiser('open', {
      filename: 'file:mydb.sqlite3?vfs=opfs',
    });
    dbId = openResponse.dbId;

It errors on the openResource promise.

Additionally, I ran this test to see if OPFS was supported:

if ('storage' in navigator && 'getDirectory' in navigator.storage) {
  console.log('OPFS is supported');
} else {
  console.log('OPFS is not supported');
}

Giving me "OPFS is supported".

I tried clearing cache but localhost still seems to work, but no other domain does.

Any help appreciated!

I recently migrated my usage of sqlite-wasm from a localhost project to a https hosted domain...

My guess is that you are not emitting the COOP/COEP headers from your remote server. Without those, the OPFS VFS will not be available because it requires the SharedArrayBuffer class (which is only available if the COOP/COEP headers are emitted):

https://sqlite.org/wasm/doc/trunk/persistence.md#coop-coep

Additionally, I ran this test to see if OPFS was supported:

That particular VFS requires more than OPFS. See the above-linked page for a separate OPFS VFS which does not have the same requirements, but also has other trade-offs.

Closing ticket, as this is a config-related error, not a library-level bug.