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

How to embed pdf.js into another module intended for use in webpack projects? #10324

Closed
marcaaron opened this issue Dec 1, 2018 · 5 comments
Closed
Labels

Comments

@marcaaron
Copy link

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:

  1. Install package as dependency
  2. 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?

@pk-nb
Copy link

pk-nb commented Dec 14, 2018

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 #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.

@marcaaron
Copy link
Author

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.

@davidawad
Copy link

So is it correct to say that you must eject from CRA in order for your project to use PDFJS?

@Snuffleupagus
Copy link
Collaborator

/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?

@timvandermeij
Copy link
Contributor

Yes, indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants