fix(13-01): use file:// worker path for pdfjs-dist 5.x fake-worker in Node.js
Empty string workerSrc is falsy — PDFWorker.workerSrc getter throws before _setupFakeWorkerGlobal can dynamically import the worker file. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user