From d5474a1bd96fd2386912807828c587834d08de20 Mon Sep 17 00:00:00 2001 From: tegwick Date: Tue, 26 May 2026 15:28:51 +0200 Subject: [PATCH] Set pdfjs GlobalWorkerOptions.workerSrc at app bootstrap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PDF.js library refuses to open documents without a worker URL. Production builds were throwing "No GlobalWorkerOptions.workerSrc specified" on any upload because neither the source-layer ingest (extract.ts) nor the viewer adapter ever set one — they relied on the host application to do it, and the browser bootstrap didn't. main.tsx now imports the worker via Vite's `?url` suffix so the file is bundled into the build, and sets GlobalWorkerOptions.workerSrc once before any PDF code runs. Added src/vite-env.d.ts so TypeScript knows about the `?url` import suffix. Co-Authored-By: Claude Opus 4.7 --- src/app/main.tsx | 9 +++++++++ src/vite-env.d.ts | 1 + 2 files changed, 10 insertions(+) create mode 100644 src/vite-env.d.ts diff --git a/src/app/main.tsx b/src/app/main.tsx index ef3196e..dcc6da4 100644 --- a/src/app/main.tsx +++ b/src/app/main.tsx @@ -1,7 +1,16 @@ import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; +import * as pdfjs from "pdfjs-dist"; +// Vite resolves `?url` to a bundled asset URL the browser can fetch. +import pdfWorkerUrl from "pdfjs-dist/build/pdf.worker.min.mjs?url"; + import { App } from "./App"; +// PDF.js needs a worker URL before any PDF is parsed. Set it once at app +// bootstrap so both the source-layer ingest (extract.ts) and the viewer +// adapter (PdfSpikeViewer) can open documents. +pdfjs.GlobalWorkerOptions.workerSrc = pdfWorkerUrl; + const container = document.getElementById("root"); if (!container) throw new Error("#root not found"); diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts new file mode 100644 index 0000000..11f02fe --- /dev/null +++ b/src/vite-env.d.ts @@ -0,0 +1 @@ +///