Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@
"inquirer": "^13.3.0",
"jose": "^6.1.3",
"json-schema-to-zod": "^2.7.0",
"mammoth": "^1.11.0",
"mediabunny": "^1.40.1",
"music-metadata": "^11.11.2",
"nanoid": "^5.1.5",
Expand Down Expand Up @@ -273,6 +272,7 @@
"@picovoice/cobra-node": "^3.0.2",
"bullmq": "^5.52.2",
"exceljs": "^4.4.0",
"mammoth": "^1.11.0",
"pdf-parse": "^2.4.5",
"pdf-to-img": "^5.0.0",
"@fastify/cors": "^11.2.0",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions src/lib/processors/document/WordProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
* ```
*/

import * as mammoth from "mammoth";

import { BaseFileProcessor } from "../base/BaseFileProcessor.js";
import type {
FileInfo,
Expand All @@ -44,6 +42,26 @@ import type {
import { SIZE_LIMITS } from "../config/index.js";
import { FileErrorCode } from "../errors/index.js";

let _mammoth: typeof import("mammoth") | null = null;
async function loadMammoth() {
if (_mammoth) {
return _mammoth;
}
try {
_mammoth = await import(/* @vite-ignore */ "mammoth");
return _mammoth;
} catch (err) {
const e = err instanceof Error ? (err as NodeJS.ErrnoException) : null;
if (e?.code === "ERR_MODULE_NOT_FOUND" && e.message.includes("mammoth")) {
throw new Error(
'Word document processing requires the "mammoth" package. Install it with:\n pnpm add mammoth',
{ cause: err },
);
}
throw err;
}
}

// Re-export for consumers who import from this module

// Import for local use
Expand Down Expand Up @@ -266,6 +284,7 @@ export class WordProcessor extends BaseFileProcessor<ProcessedWord> {
const warnings: string[] = [];

try {
const mammoth = await loadMammoth();
// Extract plain text
const textResult = await mammoth.extractRawText({ buffer });
textContent = textResult.value;
Expand Down
Loading