-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
What should be the value for workerSrc
?
#8305
Comments
@yinso should be something the browser can hit. You may not want to use a relative path since it may break if anything else in your stack makes asset digests. It is best if you render that from your web framework. |
Moreover, you can refer to the Webpack example at https://github.com/mozilla/pdf.js/tree/master/examples/webpack. Closing as answered. |
Thanks guys for the help - appreciated. |
This comment was marked as outdated.
This comment was marked as outdated.
I think @luistak solution should be added to the documentation. It's the cleanest way to load the worker in using webpack/create-react-app |
It's the cleanest way to load the worker in using webpack/create-react-app |
@luistak solution is good but still getting the error in console: Warning: Setting up fake worker. Any help? |
I use Pdfjs v2.8.335 with legacy supporting in this way: import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf' pdfjsLib.GlobalWorkerOptions.workerSrc = PDFJSWorker |
I use Pdfjs v2.9.359 with legacy supporting in this way:
|
has anyone faced error
|
Having the same issue as @iamrmin. The solution looks straightforward but crash follows... |
@Johnnybar Yes and I fixed it the same way 🤝 |
Hi @iamrmin and whoever runs into this problem in the future. I managed to solve this issue by creating an .env file in the project's root where I deactivated building sourcemaps. |
import { pdfjs } from 'react-pdf' pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker |
You have the issue because you already have an instance for the pdfWorker created, I hade the same issue and I fixed it by adding this globalThis.pdfjsWorker = null; just before setting the workerSrc |
If anyone reaches this point and uses this library in Node.js with Typescript, Serverless Framework and In your provider:
optimize:
external:
- pdfjs-dist/legacy/build/pdf.worker.js In your code: import * as pdfjs from 'pdfjs-dist/legacy/build/pdf';
pdfjs.GlobalWorkerOptions.workerSrc = 'pdfjs-dist/legacy/build/pdf.worker'; |
Adding this to the entry file is automatically set
|
me encontre con el mismo problema, y solucione asi:
Espero que a alguien le sirva :) |
For Vite users, you may try the following: import * as pdfJS from "pdfjs-dist";
import pdfJSWorkerURL from "pdfjs-dist/build/pdf.worker?url";
pdfJS.GlobalWorkerOptions.workerSrc = pdfJSWorkerURL; See: https://vitejs.dev/guide/assets.html#explicit-url-imports |
We're not allowed to rely on cloudfare's cdn, so we needed another approach.
|
zhaoxu-lingoace's solution worked for me using webpack. I did it following the instructions on worker loading in timvandermeij's example: https://github.com/mozilla/pdf.js/tree/master/examples/webpack
|
fantastic |
pdf.mjs:12095 app-index.js:33 Warning: Error: Setting up fake worker failed: "Failed to fetch dynamically imported module: http://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.6.82/pdf.worker.js". |
getting 403 |
@jigmeloday Could you please try this?
|
I haven't checked why yet but changing react-pdf version to: Edit: |
Link to PDF file (or attach file here):
Configuration:
I tried to follow the documentation for webpack but it's not working (keep getting setting up fake worker), probably due to me not understanding what exactly should go into
workerSrc
.Is
workerSrc
:PDFJS.workerSrc = '/pdf.worker.js';
e.g.
PDFJS.workerSrc = 'pdfjs-dist/build/pdf.worker.js';
e.g.
PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js';
Thanks for any pointers.
The text was updated successfully, but these errors were encountered: