diff --git a/teressa-copeland-homes/src/lib/ai/extract-text.ts b/teressa-copeland-homes/src/lib/ai/extract-text.ts index 6167522..6d94eb8 100644 --- a/teressa-copeland-homes/src/lib/ai/extract-text.ts +++ b/teressa-copeland-homes/src/lib/ai/extract-text.ts @@ -5,10 +5,12 @@ // @ts-ignore — legacy .mjs build; types re-exported from main pdfjs-dist declaration import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist/legacy/build/pdf.mjs'; import { readFile } from 'node:fs/promises'; +import { join } from 'node:path'; -// Empty string = no worker thread (fake/synchronous worker) — required for Node.js server context. -// Do NOT use: new URL('pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url) — that is browser-only. -GlobalWorkerOptions.workerSrc = ''; +// pdfjs-dist 5.x fake-worker mode: must point workerSrc to the actual worker file so +// _setupFakeWorkerGlobal can `await import(this.workerSrc)` in Node.js. +// Empty string is falsy → PDFWorker.workerSrc getter throws before the import runs. +GlobalWorkerOptions.workerSrc = `file://${join(process.cwd(), 'node_modules/pdfjs-dist/legacy/build/pdf.worker.mjs')}`; export interface PageText { page: number; // 1-indexed