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

The API version "2.3.45" does not match the Worker version "2.1.266 #10997

Closed
asalria opened this issue Jul 21, 2019 · 15 comments
Closed

The API version "2.3.45" does not match the Worker version "2.1.266 #10997

asalria opened this issue Jul 21, 2019 · 15 comments

Comments

@asalria
Copy link

asalria commented Jul 21, 2019

Attach (recommended) or Link to PDF file here:

Configuration:

  • Web browser and its version: 72.0.3626.121
  • Operating system and its version: Windows 10
  • PDF.js version:
  • Is a browser extension: No

Steps to reproduce the problem:

  1. Followed the steps on readme
  2. Installed pdfjs-dist as it was not included in node-modules

What is the expected behavior? (add screenshot)

What went wrong? (add screenshot)
image

When calling loadingTask.promise

Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):

@timvandermeij
Copy link
Contributor

pdfjs-dist is version 2.1.266, but the master branch clone is 2.3.45. Those two are incompatible. You should either only use pdfjs-dist or the master branch clone, but not a mix of both.

@wwwhatley
Copy link

I have this issue as well, and I don't believe it has anything to do with what you're saying @timvandermeij ....

"pdfjs-dist": "^2.4.456",
pdfjs.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';

Please help. Working with PDFJS has been a nightmare.

@timvandermeij
Copy link
Contributor

Given the lack of enough details here, I'm going by what you wrote and it seems to have everything to do with what I wrote earlier because you're also mixing versions here! The error is pretty clear: you're installing pdfjs-dist version 2.4.456, but the worker you're linking to is version 2.6.140 as of writing. You should never directly link to mozilla.github.io/pdf.js since it changes on every push to master. It's not meant to be a CDN. The worker file is simply bundled in pdfjs-dist so there is not even a need to link to another source...

@wwwhatley
Copy link

I appreciate the response--so what should I be referencing with pdfjs.GlobalWorkerOptions.workerSrc = ? Without it, it says
"Setting up fake worker failed: "Cannot read property 'WorkerMessageHandler' of undefined"." @timvandermeij

@wwwhatley
Copy link

And when I add pdfjs.GlobalWorkerOptions.workerSrc = '../../../node_modules/pdfjs-dist/build/pdf.worker.js'; I get the same error...

@timvandermeij
Copy link
Contributor

Looking at the various examples, for example https://github.com/mozilla/pdf.js/blob/50bc4a18e8c564753365d927d5ec6a6d2cce3072/examples/components/pageviewer.js, that should be enough. Without a running example there is not much we can do to help since it may very well be caused by something else in your code. I'd suggest to try running the examples first, see if that works and go from there.

@DevSallSa
Copy link

I know this issue is closed but I want to share my solution for those who have this problem.
Just clear your browser's cache [and cookies]

@chocoford
Copy link

For me, I use CDN and found that pdfjsLib.GlobalWorkerOptions.workerSrc should be set to same version as pdf.min.js rather than //mozilla.github.io/pdf.js/build/pdf.worker.js in Examples

<script src="https://cdn.jsdelivr.net/npm/pdfjs-dist@2.6.347/build/pdf.min.js"></script>
<script>
...

// Loaded via <script> tag, create shortcut to access PDF.js exports.
var pdfjsLib = window['pdfjs-dist/build/pdf'];

// The workerSrc property shall be specified.
pdfjsLib.GlobalWorkerOptions.workerSrc = '//cdn.jsdelivr.net/npm/pdfjs-dist@2.6.347/build/pdf.worker.js';

...
</script>

@hassamulhaq
Copy link

Fix for any release. Now use pdfjs without CDN and no Worker version error anymore.

Goto: https://github.com/mozilla/pdf.js/releases

there are four files

pdfjs-2.16.105-dist.zip    5.5 MB
pdfjs-2.16.105-legacy-dist.zip    5.71 MB
Source code (zip)
Source code (tar.gz)

Download pdfjs-2.16.105-dist.zip file. Or download pdfjs-x.xx.xxx-dist.zip of the latest release.

Extract zip in any folder like /public/plugins/pdfjs-2.16.105-dist

Inside
pdfjs-2.16.105-dist.zip there are two folders (build, web)

├── pdfjs-2.16.105-dist
├── build
│   ├── pdf.js
│   └── pdf.sandbox.js
│   └── pdf.worker.js
├── web
│   ├── cmaps
│   └── images
│   └── locale
│   └── standared_fonts


We need to use js inside the build folder.

Now add pdf.worker.js path where you declared const pdfjsLib = window['pdfjs-dist/build/pdf'];

const pdfjsLib = window['pdfjs-dist/build/pdf'];

// The workerSrc property shall be specified.
pdfjsLib.GlobalWorkerOptions.workerSrc = '../../public/plugins/pdfjs-2.16.105-dist/build/pdf.worker.js';

So, now you will never face any conflict of versions. because pdf.js and pdf.worker.js are both available in pdfjs-dist directory. Or if you want to add pdfjs using CDN then check comment by chocoford.

@hainguyenvan6799
Copy link

Fix for any release. Now use pdfjs without CDN and no Worker version error anymore.

Goto: https://github.com/mozilla/pdf.js/releases

there are four files

pdfjs-2.16.105-dist.zip    5.5 MB
pdfjs-2.16.105-legacy-dist.zip    5.71 MB
Source code (zip)
Source code (tar.gz)

Download pdfjs-2.16.105-dist.zip file. Or download pdfjs-x.xx.xxx-dist.zip of the latest release.

Extract zip in any folder like /public/plugins/pdfjs-2.16.105-dist

Inside
pdfjs-2.16.105-dist.zip there are two folders (build, web)

├── pdfjs-2.16.105-dist
├── build
│   ├── pdf.js
│   └── pdf.sandbox.js
│   └── pdf.worker.js
├── web
│   ├── cmaps
│   └── images
│   └── locale
│   └── standared_fonts


We need to use js inside the build folder.

Now add pdf.worker.js path where you declared const pdfjsLib = window['pdfjs-dist/build/pdf'];

const pdfjsLib = window['pdfjs-dist/build/pdf'];

// The workerSrc property shall be specified.
pdfjsLib.GlobalWorkerOptions.workerSrc = '../../public/plugins/pdfjs-2.16.105-dist/build/pdf.worker.js';

So, now you will never face any conflict of versions. because pdf.js and pdf.worker.js are both available in pdfjs-dist directory. Or if you want to add pdfjs using CDN then check comment by chocoford.

Hi, I updated the source code following your instruction, but it can not solve my problem. Can you give me your example source code?

@hassamulhaq
Copy link

@hainguyenvan6799 Hi.
Here is my working Pdf.js project repo: https://github.com/hassamulhaq/project-media

@gokul-afk
Copy link

I had this issue in React, Check the worker url specified in the worker component.

<Worker workerUrl="https://unpkg.com/pdfjs-dist@2.16.105/build/pdf.worker.js">

"pdfjs-dist": "^2.16.105",

mke sure its the same version as of package.json. solved it for me .

@Paelsis
Copy link

Paelsis commented Oct 4, 2023

I have tried to find a worker for 2 days.
Contradicting issues all the time.
react-pdf is a nightmare.

@jothbc
Copy link

jothbc commented May 2, 2024

I have tried to find a worker for 2 days. Contradicting issues all the time. react-pdf is a nightmare.

see this answer, hope this helps you

#17245 (comment)

@arifkk0313
Copy link

pdfjs.GlobalWorkerOptions.workerSrc = 'https://unpkg.com/pdfjs-dist@2.16.105/build/pdf.worker.js';
"pdfjs-dist": "^2.16.105",

works for me

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