Skip to content

Build your personal knowledge base with Trilium Notes

chore(server): try to bypass officeparser PDFjs issue

Elian Doran0d3f70a23191
diff --git a/apps/server/scripts/build.ts b/apps/server/scripts/build.ts
index 81985db51d..9fa1f9cb83 100644
--- a/apps/server/scripts/build.ts
+++ b/apps/server/scripts/build.ts
@@ -11,7 +11,7 @@ async function main() {
build.copy("/packages/share-theme/src/templates", "share-theme/templates/");
// Copy node modules dependencies
- build.copyNodeModules([ "better-sqlite3", "bindings", "file-uri-to-path", "pdfjs-dist" ]);
+ build.copyNodeModules([ "better-sqlite3", "bindings", "file-uri-to-path" ]);
build.copy("/node_modules/ckeditor5/dist/ckeditor5-content.css", "ckeditor5-content.css");
build.buildFrontend();
diff --git a/apps/server/src/services/ocr/processors/office_processor.ts b/apps/server/src/services/ocr/processors/office_processor.ts
index cabc07b3e0..1435ecc371 100644
--- a/apps/server/src/services/ocr/processors/office_processor.ts
+++ b/apps/server/src/services/ocr/processors/office_processor.ts
@@ -4,6 +4,15 @@ import log from '../../log.js';
import { OCRProcessingOptions, OCRResult } from '../ocr_service.js';
import { FileProcessor } from './file_processor.js';
+// officeparser depends on pdfjs-dist which expects DOMMatrix at the
+// top level. Provide a minimal stub so it doesn't crash in Node.js
+// environments that lack it (e.g. Alpine Linux).
+if (!globalThis.DOMMatrix) {
+ globalThis.DOMMatrix = class DOMMatrix {
+ a = 1; b = 0; c = 0; d = 1; e = 0; f = 0;
+ } as unknown as typeof globalThis.DOMMatrix;
+}
+
const SUPPORTED_TYPES = [
// Office Open XML
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', // DOCX