Просмотр исходного кода

fix: lazy-load node:sqlite for Node 20 compatibility

Ma 7 месяцев назад
Родитель
Сommit
310895e688
1 измененных файлов с 5 добавлено и 2 удалено
  1. 5 2
      packages/core/src/state/memory-db.ts

+ 5 - 2
packages/core/src/state/memory-db.ts

@@ -9,7 +9,6 @@
  * persistence layer. MemoryDB is an acceleration index built alongside them.
  */
 
-import { DatabaseSync } from "node:sqlite";
 import { join } from "node:path";
 
 export interface Fact {
@@ -34,9 +33,13 @@ export interface StoredSummary {
 }
 
 export class MemoryDB {
-  private db: InstanceType<typeof DatabaseSync>;
+  // eslint-disable-next-line @typescript-eslint/no-explicit-any
+  private db: any;
 
   constructor(bookDir: string) {
+    // Dynamic import to avoid crashing on Node 20 (node:sqlite requires Node 22+)
+    // eslint-disable-next-line @typescript-eslint/no-require-imports
+    const { DatabaseSync } = require("node:sqlite");
     const dbPath = join(bookDir, "story", "memory.db");
     this.db = new DatabaseSync(dbPath);
     this.db.exec("PRAGMA journal_mode = WAL");