{"record":{"id":"ca4c5874ebd3d5ed","repo":"decolua/9router","slug":"db-better-sqlite3-unavailable-e-message","errorCode":null,"errorMessage":"[DB] better-sqlite3 unavailable: ${e.message}","messagePattern":"\\[DB\\] better-sqlite3 unavailable: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/lib/db/driver.js","lineNumber":26,"sourceCode":"  // Bun runtime only — built-in, no install needed\n  if (!process.versions.bun) return null;\n  try {\n    const { createBunSqliteAdapter } = await import(\"./adapters/bunSqliteAdapter.js\");\n    return await createBunSqliteAdapter(DATA_FILE);\n  } catch (e) {\n    console.warn(`[DB] bun:sqlite unavailable: ${e.message}`);\n    return null;\n  }\n}\n\nasync function tryBetterSqlite() {\n  // Skip on Bun — better-sqlite3 native bindings unsupported\n  if (process.versions.bun) return null;\n  try {\n    const { createBetterSqliteAdapter } = await import(\"./adapters/betterSqliteAdapter.js\");\n    return createBetterSqliteAdapter(DATA_FILE);\n  } catch (e) {\n    console.warn(`[DB] better-sqlite3 unavailable: ${e.message}`);\n    return null;\n  }\n}\n\nasync function tryNodeSqlite() {\n  // 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","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/lib/db/driver.js#L8-L44","documentation":"Second link in the driver fallback chain. tryBetterSqlite attempts to load the optional native better-sqlite3 dependency; on any import or init failure (it is skipped entirely under Bun), it logs this warning and returns null so the chain continues with node:sqlite. Because better-sqlite3 is only in optionalDependencies, failure is expected on machines without native build tools.","triggerScenarios":"Node runtime where better-sqlite3 is not installed (skipped optional dep), its native binding was built for a different Node ABI (NODE_MODULE_VERSION mismatch after a Node upgrade), the build failed during npm install (missing node-gyp/python/compilers), or createBetterSqliteAdapter cannot open DATA_FILE.","commonSituations":"Upgrading Node versions without reinstalling; npm install --omit=optional; Alpine/scratch containers lacking build toolchain; Electron/Node ABI mismatch.","solutions":["Run npm install (or npm rebuild better-sqlite3) to rebuild the native module for the current Node version.","Install build prerequisites (python3, make, g++) if the install log showed a build failure.","Rely on the fallback: Node >= 22.5 uses built-in node:sqlite — nothing to fix.","Ensure DATA_FILE's directory is writable and the file isn't corrupt/locked."],"exampleFix":"// before\nNode upgraded 20 -> 22, better-sqlite3 binding stale\n// after\nnpm rebuild better-sqlite3   # or: npm install","handlingStrategy":"fallback","validationCode":"try { await import(\"better-sqlite3\"); console.log(\"better-sqlite3 OK\"); }\ncatch (e) { console.warn(\"better-sqlite3 missing/mismatched — run npm rebuild better-sqlite3\"); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["After any Node version change, run npm rebuild better-sqlite3 to match the new ABI.","Don't install with --omit=optional if you want the native driver.","Provide build tools (python3, make, g++) in CI/container images.","Log adapter.driver at startup to detect silent fallback to node:sqlite/sql.js."],"tags":["sqlite","native-module","node","driver-fallback"],"backgroundTag":"sqlite-driver-unavailable","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}