fix: downgrade pdf-parse to 1.1.1 to eliminate native dependency

pdf-parse@2.4.5 depends on @napi-rs/canvas (native Skia binary compiled
with AVX instructions) which crashes with SIGILL on the Synology NAS CPU.
Version 1.1.1 is pure JavaScript and works on any architecture.
This commit is contained in:
vakabunga
2026-03-14 14:03:14 +03:00
parent 5fa6b921d8
commit 723df494ca
4 changed files with 34 additions and 237 deletions

View File

@@ -18,7 +18,7 @@
"express": "^5.2.1",
"multer": "^2.1.1",
"openai": "^6.27.0",
"pdf-parse": "^2.4.5",
"pdf-parse": "1.1.1",
"pg": "^8.19.0",
"uuid": "^13.0.0"
},

View File

@@ -63,17 +63,9 @@ export function isPdfConversionError(r: unknown): r is PdfConversionError {
);
}
// Lazy-loaded to avoid crashing the app at startup — pdf-parse pulls in
// @napi-rs/canvas (native Skia binary) which may fail on Alpine.
let _PDFParse: typeof import('pdf-parse')['PDFParse'] | undefined;
function loadPDFParse() {
if (!_PDFParse) {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const mod = require('pdf-parse') as typeof import('pdf-parse');
_PDFParse = mod.PDFParse;
}
return _PDFParse;
}
// pdf-parse v1 default export: (buffer, options?) => Promise<{ text, numpages, info }>
// eslint-disable-next-line @typescript-eslint/no-require-imports
const pdfParse: (buf: Buffer) => Promise<{ text: string }> = require('pdf-parse');
export async function convertPdfToStatement(
buffer: Buffer,
@@ -88,11 +80,8 @@ export async function convertPdfToStatement(
let text: string;
try {
const PDFParse = loadPDFParse();
const parser = new PDFParse({ data: buffer });
const result = await parser.getText();
const result = await pdfParse(buffer);
text = result.text || '';
await parser.destroy();
} catch (err) {
console.error('PDF extraction error:', err);
return {