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

Setting up fake worker failed: "Cannot read property 'WorkerMessageHandler' of undefined" #11990

Closed
dharmatv opened this issue Jun 11, 2020 · 6 comments

Comments

@dharmatv
Copy link

Configuration:
Chrome version: 81.0.4044.129
OS: Ubuntu
PDF.js version: Using pdf-dist npm module(https://www.npmjs.com/package/pdfjs-dist)
Is a browser extension: No

Pdf file is: http://www.africau.edu/images/default/sample.pdf

Problem:
I am using a pdf-dist library, It was working correctly, but suddenly got an issue like the following picture
https://snipboard.io/A67H4J.jpg

Could you guys please provide any solution.

@Snuffleupagus
Copy link
Collaborator

PDF.js version: Using pdf-dist npm module(https://www.npmjs.com/package/pdfjs-dist)

Please provide the actual version number when opening an issue.

[...] but suddenly got an issue like the following picture

(Generally speaking, it's always easier/quicker for people if you actually attach screen-shots directly to the issue rather than linking to it.)

The screen-shot clearly shows that you haven't setup the PDF.js library correctly, based on the warning messages, since you should always ensure that the workerSrc property is set correctly such that the pdf.worker.js file can be found/loaded; basically you need to add a line looking something like the below (obviously with the path adjusted as necessary for your deployment) before calling pdfjsLib.getDocument(...) or doing anything else:

pdfjsLib.GlobalWorkerOptions.workerSrc = "../some/path/to/pdf.worker.js";

Finally, please note that this is a bug tracker rather than a support forum and that this issue is missing too many details to be actionable/valid; please also see https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md (emphasis mine):

If you are developing a custom solution, first check the examples at https://github.com/mozilla/pdf.js#learning and search existing issues. If this does not help, please prepare a short well-documented example that demonstrates the problem and make it accessible online on your website, JS Bin, GitHub, etc. before opening a new issue or contacting us in the Matrix room -- keep in mind that just code snippets won't help us troubleshoot the problem.

@dharmatv
Copy link
Author

dharmatv commented Jun 11, 2020

pdfjs-dist: 2.2.228

@gold3bear
Copy link

const pdfjs = require("pdfjs-dist");
pdfjs.GlobalWorkerOptions.workerSrc = require("pdfjs-dist/build/pdf.worker.entry.js");

@Nataliasem
Copy link

I use Pdfjs v2.8.335 with legacy supporting in this way:

import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf'
import PDFJSWorker from 'pdfjs-dist/legacy/build/pdf.worker.entry'

pdfjsLib.GlobalWorkerOptions.workerSrc = PDFJSWorker

@Lgowen
Copy link

Lgowen commented Sep 2, 2021

const pdfjs = require("pdfjs-dist");
pdfjs.GlobalWorkerOptions.workerSrc = require("pdfjs-dist/build/pdf.worker.entry.js");

In order not to increase the size of the mobile product dependent package, is there any other way we can solve it?

@LePhenix47
Copy link

const pdfjs = require("pdfjs-dist");
pdfjs.GlobalWorkerOptions.workerSrc = require("pdfjs-dist/build/pdf.worker.entry.js");

Thank you

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

No branches or pull requests

7 participants