Webpack instructions still cause 'fake worker' to load
See original GitHub issueConfiguration:
- Web browser and its version: Chrome 52
- Operating system and its version: OS X Yosemite
- PDF.js version: 1.4.237
- Is an extension: No
Steps to reproduce the problem: My code is:
import pdflib from 'pdfjs-dist'
pdflib.PDFJS.workerSrc = './node_modules/pdfjs-dist/build/pdf.worker.entry.js'
exactly as described in https://github.com/mozilla/pdf.js/wiki/Setup-pdf.js-in-a-website#with-webpack,
yet I get a Warning: Setting up fake worker.'
in my console when I actually load a document, which makes it seem like the instructions did not work.
Additionally the wording on the instructions seems wrong as “PDFJS.workerSrc shall be set to point to this file” (the current wording) means that it’s automatically set, whereas “PDFJS.workerSrc should be set to point to this file” means you have to set it yourself.
The example code also isn’t extremely helpful as it uses the relative paths into the repository (pdfjsLib.PDFJS.workerSrc = '../../build/webpack/pdf.worker.bundle.js';
) that a person importing PDFJS would not be able to do.
I’m also confused as I searched through issues/PRs that are < 1 year old like https://github.com/mozilla/pdf.js/pull/6595 that do some automatic loading of the worker script, but that code seems to no longer exist in the repo, so both setting and not setting the workerSrc
cause the fake worker to load for me… The fake worker knows where to find the worker script built by webpack (e.g. 1.bundle.js
is the worker when bundle.js
is the script), so I’m confused why a real worker couldn’t use this logic as well.
I’ve tried pointing workerSrc
to the 1.bundle.js
file created and even using webpack’s worker-loader to instantiate and replace PDFWorker
(pdflib.PDFJS.PDFWorker = require('worker!pdfjs-dist/build/pdf.worker.entry.js')
), but that didn’t work either, so I’m completely lost as to how the worker is supposed to work with webpack
Issue Analytics
- State:
- Created 7 years ago
- Reactions:8
- Comments:32 (11 by maintainers)
Top GitHub Comments
I ran into the same issue with my webpack project, but I solved it differently. Instead of relying on webpack’s bundling or loaders, I made use of the CopyWebpackPlugin to copy the worker source into my build directory.
In my viewer:
In
webpack.config.js
:@wojtekmaj we added pdfjs-dist/webpack for zero-configuration for webpack users. You can see its usage at https://github.com/yurydelendik/pdfjs-react