[Bug]: pdfjs-dist Worker Import Fails in Vite – Requires Manual WorkerSrc Assignment #19520
Unanswered
JanWohlgehagen
asked this question in
Q&A
Replies: 1 comment
-
I'm also running pdfjs v4 in vite and found this works:
(We're running a legacy build, but I assume the main build works the same way) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Attach (recommended) or Link to PDF file
Version 4 onwards (I assume), doesn't provide the worker in a format that Vite can resolve easily.
The workaround I found: https://stackoverflow.com/questions/79044550/how-to-use-pdfjs-worker-in-react-and-typescript
I was running angular 19.
Web browser and its version
Edge: ultat: Version 133.0.3065.69 (Officielt build) (64-bit), Safari: 17.6
Operating system and its version
Windows: 11 24H2, Mac OS: Sonoma 14.7.4
PDF.js version
4.10.38
Is the bug present in the latest PDF.js version?
Yes
Is a browser extension
No
Steps to reproduce the problem
This worked with pdfjs-dist 3.11.174 (which is what I bumped from), e.g.:
import { WorkerTask } from 'pdfjs-dist/build/pdf.worker.js';
GlobalWorkerOptions.workerSrc = WorkerTask;
getDocument(this.currentUrl).promise.then(
(doc) => {...}
);
What is the expected behavior?
Should open the PDF in a view.
What went wrong?
Throws a browser alert.
Link to a viewer
No response
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions