Skip to content
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

Merged
merged 1 commit into from Jul 26, 2023

Conversation

marcelpanse
Copy link

Problem

Error: Setting up fake worker failed: \"No \"GlobalWorkerOptions.workerSrc\" specified.\"."

Closes #64

Solution

Setting the workerSrc in lib/util/pdf.js

@LoneRifle
Copy link

LoneRifle commented Jul 13, 2023

A quick googling shows that there are multiple possible options to set workerSrc to.

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

@LoneRifle LoneRifle closed this Jul 13, 2023
@LoneRifle LoneRifle reopened this Jul 13, 2023
@LoneRifle LoneRifle closed this Jul 13, 2023
@marcelpanse
Copy link
Author

This was that approach suggested in that issue: mozilla/pdf.js#10478 (comment)
So I'm not sure what other approaches you are referring to?

@LoneRifle
Copy link

Could you consider mozilla/pdf.js#10478 (comment) instead?

@marcelpanse
Copy link
Author

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)

@LoneRifle
Copy link

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 GlobalWorkerOptions.workerSrc is missing.

@marcelpanse
Copy link
Author

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 :-)

@LoneRifle
Copy link

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?

@marcelpanse
Copy link
Author

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.

@marcelpanse
Copy link
Author

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:
https://codesandbox.io/p/sandbox/proud-silence-yn6mhx?file=%2Fpackage.json%3A9%2C5

This is the same code but with my PR that fixes it:
https://codesandbox.io/p/sandbox/pdf2md-fork-zqq6j5?file=%2Findex.js%3A10%2C45

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 ;-)

@LoneRifle LoneRifle reopened this Jul 26, 2023
Copy link

@LoneRifle LoneRifle left a 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

@LoneRifle LoneRifle merged commit 713546c into opengovsg:master Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: Setting up fake worker failed: "No "GlobalWorkerOptions.workerSrc" specified."."
2 participants