I 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:
create-react-app
projectWhat 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?
I believe this is not an issue with nesting in the package, but instead with the requireEnsure
config being turned off in create-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.
Ah I see... Well, thanks @pk-nb! I did see some discussion over on the react repo for potentially adding web workers, but not sure if this ever panned out or would improve things for pdfjs and CRA users.
So is it correct to say that you must eject from CRA in order for your project to use PDFJS?
/cc @timvandermeij Given the example added in PR #11220, and that the Critical dependency: ...
warnings should have been removed in PR #11418, should this issue be closed now?
Yes, indeed.
Most helpful comment
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.