decolua/9router · warning

[DB] sql.js unavailable: ${e.message}

Error message

[DB] sql.js unavailable: ${e.message}

What it means

Last link in the driver fallback chain. trySqlJs loads the pure-JS sql.js adapter, which always works in principle; if its import or initialization fails, this warning is logged and null is returned. If all four drivers fail, initAdapter throws '[DB] No SQLite driver available'.

Source

Thrown at src/lib/db/driver.js:50

  // Built-in since Node 22.5.0 — no install needed. Skip under Bun (no node:sqlite).
  if (process.versions.bun) return null;
  const [maj, min] = process.versions.node.split(".").map(Number);
  if (maj < 22 || (maj === 22 && min < 5)) return null;
  try {
    const { createNodeSqliteAdapter } = await import("./adapters/nodeSqliteAdapter.js");
    return await createNodeSqliteAdapter(DATA_FILE);
  } catch (e) {
    console.warn(`[DB] node:sqlite unavailable: ${e.message}`);
    return null;
  }
}

async function trySqlJs() {
  try {
    const { createSqlJsAdapter } = await import("./adapters/sqljsAdapter.js");
    return await createSqlJsAdapter(DATA_FILE);
  } catch (e) {
    console.warn(`[DB] sql.js unavailable: ${e.message}`);
    return null;
  }
}

async function initAdapter() {
  ensureDirs();
  // Order per runtime:
  //   Bun:  bun:sqlite → sql.js
  //   Node: better-sqlite3 → node:sqlite (≥22.5) → sql.js
  let adapter = await tryBunSqlite();
  if (!adapter) adapter = await tryBetterSqlite();
  if (!adapter) adapter = await tryNodeSqlite();
  if (!adapter) adapter = await trySqlJs();
  if (!adapter) throw new Error("[DB] No SQLite driver available (bun/better/node/sql.js all failed)");

  if (!state.logged) {
    console.log(`[DB] Driver: ${adapter.driver} | file: ${DATA_FILE}`);
    state.logged = true;

View on GitHub (pinned to 90b52e06ff)

Solutions

  1. Reinstall dependencies: rm -rf node_modules && npm install (restores sql.js and its wasm assets).
  2. Check e.message for WASM-load errors and ensure the bundler/deploy includes sql.js's .wasm file.
  3. Verify the data directory is writable — sql.js must persist DATA_FILE.
  4. Fix one of the earlier drivers (rebuild better-sqlite3 or upgrade Node) so sql.js is not needed.

Example fix

// before
node_modules partially installed, sql.js wasm missing
// after
rm -rf node_modules package-lock.json && npm install
Defensive patterns

Strategy: fallback

Validate before calling

try { const m = await import("sql.js"); console.log("sql.js OK (final fallback)"); }
catch (e) { console.error("sql.js broken — DB will fail to initialize", e.message); }

Try / catch

try { await getAdapter(); }
catch (e) {
  if (e.message.includes("No SQLite driver")) {
    console.error("All drivers failed. Fix node_modules and disk access, then restart.");
  }
}

Prevention

When it happens

Trigger: createSqlJsAdapter throws: the sql.js package (a dependency) is missing or fails to load its WASM binary, the dynamic import of ./adapters/sqljsAdapter.js fails, or the DATA_FILE path is invalid/unwritable (sql.js persists the DB back to disk).

Common situations: Broken node_modules (partial install); environments where sql.js cannot locate/compile its wasm file (edge runtimes, aggressive bundlers); read-only filesystem preventing persistence; all native drivers unavailable AND sql.js also broken — leading to the final 'No SQLite driver' crash.

Related errors


AI-assisted analysis of decolua/9router@90b52e06ff (2026-08-30). Data as JSON: /api/errors/364b753c6e128109. Report an issue: GitHub.