{"record":{"id":"364b753c6e128109","repo":"decolua/9router","slug":"db-sql-js-unavailable-e-message","errorCode":null,"errorMessage":"[DB] sql.js unavailable: ${e.message}","messagePattern":"\\[DB\\] sql\\.js unavailable: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/lib/db/driver.js","lineNumber":50,"sourceCode":"  // Built-in since Node 22.5.0 — no install needed. Skip under Bun (no node:sqlite).\n  if (process.versions.bun) return null;\n  const [maj, min] = process.versions.node.split(\".\").map(Number);\n  if (maj < 22 || (maj === 22 && min < 5)) return null;\n  try {\n    const { createNodeSqliteAdapter } = await import(\"./adapters/nodeSqliteAdapter.js\");\n    return await createNodeSqliteAdapter(DATA_FILE);\n  } catch (e) {\n    console.warn(`[DB] node:sqlite unavailable: ${e.message}`);\n    return null;\n  }\n}\n\nasync function trySqlJs() {\n  try {\n    const { createSqlJsAdapter } = await import(\"./adapters/sqljsAdapter.js\");\n    return await createSqlJsAdapter(DATA_FILE);\n  } catch (e) {\n    console.warn(`[DB] sql.js unavailable: ${e.message}`);\n    return null;\n  }\n}\n\nasync function initAdapter() {\n  ensureDirs();\n  // Order per runtime:\n  //   Bun:  bun:sqlite → sql.js\n  //   Node: better-sqlite3 → node:sqlite (≥22.5) → sql.js\n  let adapter = await tryBunSqlite();\n  if (!adapter) adapter = await tryBetterSqlite();\n  if (!adapter) adapter = await tryNodeSqlite();\n  if (!adapter) adapter = await trySqlJs();\n  if (!adapter) throw new Error(\"[DB] No SQLite driver available (bun/better/node/sql.js all failed)\");\n\n  if (!state.logged) {\n    console.log(`[DB] Driver: ${adapter.driver} | file: ${DATA_FILE}`);\n    state.logged = true;","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/lib/db/driver.js#L32-L68","documentation":"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'.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Reinstall dependencies: rm -rf node_modules && npm install (restores sql.js and its wasm assets).","Check e.message for WASM-load errors and ensure the bundler/deploy includes sql.js's .wasm file.","Verify the data directory is writable — sql.js must persist DATA_FILE.","Fix one of the earlier drivers (rebuild better-sqlite3 or upgrade Node) so sql.js is not needed."],"exampleFix":"// before\nnode_modules partially installed, sql.js wasm missing\n// after\nrm -rf node_modules package-lock.json && npm install","handlingStrategy":"fallback","validationCode":"try { const m = await import(\"sql.js\"); console.log(\"sql.js OK (final fallback)\"); }\ncatch (e) { console.error(\"sql.js broken — DB will fail to initialize\", e.message); }","typeGuard":null,"tryCatchPattern":"try { await getAdapter(); }\ncatch (e) {\n  if (e.message.includes(\"No SQLite driver\")) {\n    console.error(\"All drivers failed. Fix node_modules and disk access, then restart.\");\n  }\n}","preventionTips":["Keep node_modules healthy — reinstall on any partial-install suspicion.","Ensure the deploy/bundler includes sql.js's wasm asset when packaging.","Guarantee a writable data directory since sql.js must persist DATA_FILE.","Alert on '[DB] Driver: sql.js' at startup — you're on the slowest path."],"tags":["sqlite","sqljs","driver-fallback","wasm"],"backgroundTag":"sqlite-driver-unavailable","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}