Skip to content

Build your personal knowledge base with Trilium Notes

refactor(import): lazy-load sax in ENEX importer

Elian Doran578f57d2bd2b
diff --git a/packages/trilium-core/src/services/import/enex.ts b/packages/trilium-core/src/services/import/enex.ts
index 36ff486129..d6e0ded2ce 100644
--- a/packages/trilium-core/src/services/import/enex.ts
+++ b/packages/trilium-core/src/services/import/enex.ts
@@ -1,5 +1,4 @@
import type { AttributeType } from "@triliumnext/commons";
-import sax from "sax";
import type BNote from "../../becca/entities/bnote.js";
import * as utils from "../utils/index.js";
@@ -55,6 +54,9 @@ let note: Partial<Note> = {};
let resource: Resource;
async function importEnex(taskContext: TaskContext<"importNotes">, file: File, parentNote: BNote): Promise<BNote> {
+ // Imported dynamically so sax's module initialization is deferred to the first ENEX import
+ // rather than running at server startup (enex.ts is otherwise in the eager route graph).
+ const sax = (await import("sax")).default;
const parser = sax.parser(true);
const rootNoteTitle = file.originalname.toLowerCase().endsWith(".enex") ? file.originalname.substr(0, file.originalname.length - 5) : file.originalname;