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

webworker problem react / vite #245

Open
gandarufu opened this issue Nov 5, 2024 · 2 comments
Open

webworker problem react / vite #245

gandarufu opened this issue Nov 5, 2024 · 2 comments
Labels
question Further information is requested

Comments

@gandarufu
Copy link

I cannot get pdf-to-img working, I get the following error
The file does not exist at "/node_modules/.vite/deps/build/pdf.worker.mjs?worker_file&type=module" which is in the optimize deps directory. The dependency might be incompatible with the dep optimizer. Try adding it to optimizeDeps.exclude.

In another project I solved it by importing
import * as pdfjsLib from "pdfjs-dist/webpack";

Would that be an option?

@k-yle
Copy link
Owner

k-yle commented Nov 13, 2024

This is a NodeJS package, it's not meant to work in the browser.

In a browser, we can access the native <canvas /> element, so most of the logic in this library is not required

@k-yle k-yle added the question Further information is requested label Nov 13, 2024
@spencermize
Copy link

I'm having a similar issue - I'm not using it on the frontend, but instead in a Next.js / Webpack backend. I still get the same error:

Failed to parse document: Atel letter.pdf Error: Setting up fake worker failed: "Cannot find module '/sites/web/.next/server/vendor-chunks/pdf.worker.mjs' imported from /sites/web/.next/server/vendor-chunks/pdfjs-dist.js".
    at eval (webpack-internal:///(rsc)/../node_modules/pdfjs-dist/legacy/build/pdf.mjs:8581:36)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Any advice would be appreciated, thanks!

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

No branches or pull requests

3 participants