Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDBBatchAtomicVFS error: TypeError: Cannot read properties of null (reading 'fileSize') #137

Closed
thanhnguyen2187 opened this issue Dec 18, 2023 · 4 comments
Labels
expected behavior This doesn't seem right

Comments

@thanhnguyen2187
Copy link

Hi!

Thanks for the awesome library. I'm toying around with it to make a "full-stack" SQLite web application (SQLite persistence in browser and SQLite in the server). However, I encountered a strange error, trying to make IDBBatchAtomicVFS works. My code is something like this:

import * as IDBBatchAtomicModule from 'wa-sqlite/src/examples/IDBBatchAtomicVFS.js'

export async function hello() {
  const module = await SQLiteESMFactory()
  const sqlite3 = SQLite.Factory(module)
  const vfs = new IDBBatchAtomicModule['IDBBatchAtomicVFS']([])
  await vfs.isReady
  sqlite3.vfs_register(vfs, true)
  const db = await sqlite3.open_v2('mydb')
  const queryContent = (await import('../../../queries/01__snippet_creation.sql?raw')).default
  await sqlite3.exec(
    db,
    queryContent,
  )
  await sqlite3.close(db);
}

Where queryContent is something like:

CREATE TABLE IF NOT EXISTS snippets (
    id TEXT PRIMARY KEY,
    "name" TEXT,
    "language" TEXT,
    "text" TEXT,
    "encrypted" BOOLEAN,
    position REAL,
    updated_at DATETIME,
    created_at DATETIME
);

The error is like this:

TypeError: Cannot read properties of null (reading 'fileSize')
    at #xWriteHelper (IDBBatchAtomicVFS.js:247:40)
    at IDBBatchAtomicVFS.xWrite (IDBBatchAtomicVFS.js:232:17)
    at Ic (wa-sqlite.mjs?url:70:51)
    at wa-sqlite.wasm:0x70b37
    at wa-sqlite.wasm:0x57d2c
    at wa-sqlite.wasm:0x57ecf
    at wa-sqlite.wasm:0x2329
    at wa-sqlite.wasm:0x3f6f0
    at wa-sqlite.wasm:0x15241
    at wa-sqlite.wasm:0x5f3f7

Do you have any idea how does this error happen and what can I do to fix it? I'm using Vite, installing the library from GitHub with yarn install rhashimoto/wa-sqlite, but still serving the .mjs and .wasm files as static files.

Many thanks!

@thanhnguyen2187
Copy link
Author

For full reproducibility, you can checkout this branch of my code (thanhnguyen2187/crypta#28), then do yarn install, yarn dev, and look at the console log.

@rhashimoto
Copy link
Owner

Based on the filename in your stack trace, I suspect you're using the non-Asyncify build (wa-sqlite.{mjs,wasm}). IDBBatchAtomicVFS requires the Asyncify build (wa-sqlite-async.{mjs,wasm}).

@thanhnguyen2187
Copy link
Author

thanhnguyen2187 commented Dec 18, 2023

Oh I see. That really makes sense. I changed the importing to wa-sqlite-async.mjs and it worked. Many thanks for your help!

Maybe a document on how to use the example VFSs would be really helpful. What do you think?

@rhashimoto rhashimoto added the expected behavior This doesn't seem right label Dec 18, 2023
@rhashimoto
Copy link
Owner

There is this entry in the FAQ, and sample application code under demo/. It might be good to add a hello-async demo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expected behavior This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants