New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set pdf worker using GlobalWokerOptions.workerSrc in pdf.js #65
Conversation
A quick googling shows that there are multiple possible options to set I'll close this for now, but I look forward to another PR that tries some of the approaches specified in mozilla/pdf.js#10478 |
This was that approach suggested in that issue: mozilla/pdf.js#10478 (comment) |
Could you consider mozilla/pdf.js#10478 (comment) instead? |
No that seems incorrect. The code he references returns the required worker, but doesn't assign it, so just importing it won't do anything, you have to assign it to the GlobalWorkerOptions.workerSrc otherwise it won't do anything. The first comment on the issue also explains that: mozilla/pdf.js#10478 (comment) |
See mozilla/pdf.js#10478 (comment) . tldr, the import will establish the fallback mechanism that pdf.js uses in the event that |
Ah yes, if you have a window object. I'm running in Node, there is no window object, that was why it wasn't working in the first place :-) |
That's odd, since I'm also running this on Node, and don't observe the problems you have. Do you have a reproducible test case? Which version of node are you using? |
I'm using node 18 on OSX (arm64). I can't reproduce it in a standalone node app, I think it has something to do with the fact we compile with esbuild. Esbuild might remove some implicit dependencies. I'll look into it more later when I have some more time. |
Yeah so the problem is esbuild. I guess the default fallback mechanism that dynamically requires some file doesn't work because esbuild tree-shakes everything away. Here is the example with esbuild that doesn’t work: This is the same code but with my PR that fixes it: Disclaimer: I'm literally using pdf.js for 1 day, so I'm far from an expert or capable of judging if this is the best approach ;-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be harmless enough. lgtm
Problem
Error:
Setting up fake worker failed: \"No \"GlobalWorkerOptions.workerSrc\" specified.\"."
Closes #64
Solution
Setting the workerSrc in
lib/util/pdf.js