How to embed pdf.js into another module intended for use in webpack projects?
See original GitHub issueI created a simple module for converting PDFs to image data URLs within React apps here:
https://github.com/marcaaron/react-pdf-to-image
If I import this into a webpack project e.g. create-react-app
and then build / serve this project all goes well. But in development mode I receive the following error message in JS console.
bootstrap:1 Uncaught ReferenceError: window is not defined
And webpack dev server complains about this:
./node_modules/pdfjs-dist/build/pdf.js Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
Steps to reproduce the problem:
- Install package as dependency
- Attempt to use in a
create-react-app
project
What is the expected behavior? There would be some sort of way to add pdf.js with a worker as a dependency for other projects in development out of the box. Is this a limitation of web workers in general? Or can changes be made to the current distribution to allow this to work in all projects?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top GitHub Comments
I believe this is not an issue with nesting in the package, but instead with the
requireEnsure
config being turned off increate-react-app
.See https://github.com/mozilla/pdf.js/issues/10253. Unfortunately the only way to adjust this config currently is to eject from CRA. We have our own config where we turned this off. I wonder if PDFjs could support dynamic imports instead going forward as they are now a standard.
Yes, indeed.