tursodatabase / tursodatabase/libsql-client-ts

Unable to load db file from Wasm/StackBlitz

Open
#286 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
576
Forks
69
PR merge metrics
No merged PRs in 30d

Description

Hello,

I'm trying to create a full-stack project that will both contain the DB itself and the front-end with a back-office and a client-facing web-app. I thought trying to use libsql for this would be appropriate.

I tried to get started using StackBlitz's Bolt platform to generate a Next.js project but quickly ran into this error:

Module not found: Can't resolve './'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/@libsql/client/node_modules/@libsql/libsql-wasm-experimental/node.mjs
./node_modules/@libsql/client/lib-esm/wasm.js
./lib/db.ts
./app/page.tsx

In db.ts I create a file database using @libsql/client and in app/page.tsx I call the db to retrieve resources to render. Here is a light reproduction → from the Next.js starter on StackBlitz.

I tried to fix it by using an in-memory db or importing from @libsql/client-wasm to no avail. Then, I started from scratch, saw that this libsql demo on StackBlitz → is working and tried to build from there.

What I can't understand is where the db file is stored? Trying to initialize the client with a local file works outside of Wasm but on StackBlitz it always fails with this error: (StackBlitz →)

Error: SQLITE_CANTOPEN: sqlite3 result code 14: unable to open database file
    at async ModuleLoader.import (https://nodezjhahv-rpb4.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:154:2688)
    at async loadESM (https://nodezjhahv-rpb4.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:184:541)
    at async handleMainPromise (https://nodezjhahv-rpb4.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:165:296) {
  resultCode: 14,
  name: 'SQLite3Error'
}

I feel like these are two intertwined issues as they involve the way the package works with Wasm environments.

Possibly related issues:

  • #159 StackBlitz support?
  • I also saw another still open issue that said the Wasm code wasn't bundled yet but can't find it again, and it does seem to be bundled.

Environment

  • @libsql/client: 0.14.0 (@libsql/client-wasm)
  • next: 13.5.1
  • node: v18.20.3

Thanks in advance for your help!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked StackBlitz reproductions and inspect lib/db.ts, app/page.tsx, and the @libsql client WASM entry points shown in the import trace. Reproduce both the module-resolution and SQLITE_CANTOPEN errors, then identify whether the failure is caused by bundling or local database-file access; done means the cause and a supported fix or limitation are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, sqlite, typescript, wasm
Domain
databases, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.