-
-
Notifications
You must be signed in to change notification settings - Fork 903
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
[v6] "Could not read from file: /myrepo/node_modules/pdfjs-dist/build/pdf.worker.js?url" when using Vite specific entry #1148
Comments
Out of curiosity, how does parcel2 entry works for you in Vite? |
Thanks for the quick reply! Neither of the parcel entries cause an error at the dev server level, but they don't properly load the worker file in the browser, since it seems they result in the wrong worker file path. Trying the
Trying the
|
I'm sorry, it seems the particular error above with the When I visit the Vite dev URL directly with the
So it seems that worker path isn't valid for loading via Vite somehow anyway (though was blocked outright when using a separate origin). I don't run into either of these sorts of problem with the workaround mentioned in my original bug report where I import the worker URL directly. |
Damn, I'm puzzled. It was working fine when react-pdf was part of the workspace, but indeed stopped working when I took the sample Vite repo out of the react-pdf workspace. One thing I know is this has nothing to do with Yarn Classic, same can be reproduce in any other package manager. |
|
Working! thanks! |
Thank you guys for the heads up! |
Thank you for the speedy fix! It loads now for me now, but I now get a console warning |
I still think the original solution should have worked, as I was unable to find anything about using |
Thanks for testing and documenting that issue for Vite so thoroughly, hope they're able to determine a fix! |
OH MY GOD. It took me 4 hours to figure out that Vite is sensitive to extensions being added or not - the fix was to add
I quit |
Haha funky bugs with Vite, thank you so much for your time and perseverance through all the Vite quirks! The 6.0.2 version works for me 🎉 I ran into one gotcha when I switched to the 6.0.2 Vite entry point though, documenting here in case it's useful to others. When I first switched to using
Based on past react-pdf filed issues, it seems this occurs when the "resolutions": {
"old-package-name/pdfjs-dist": "2.16.105"
}, This triggers a warning during |
By coincidence, I'm currently attempting to migrate my project to pnpm, and the Vite entry file no longer works, as I get a 504 trying to load the PDF worker file:
(For what it's worth, this happens even with a package.json I found that this 504 error can be fixed by installing |
Before you start - checklist
Description
When I try to use the new
react-pdf
Vite entry, it causes an error which prevents the Vite server from responding whatsoever (✘ [ERROR] Could not read from file: /myrepo/node_modules/pdfjs-dist/build/pdf.worker.js?url
). Perhaps this is related to which package manager is used, but I have only tried yarn classic.A workaround that did the trick for me for now is to add
pdfjs-dist
to my dependencies directly, use the standardreact-pdf
import, and mimmic the Vite entrypoint's import the pdf worker file, like:The above works without issue. It seems Vite can only not resolve
import pdfjsWorker from "pdfjs-dist/build/pdf.worker?url";
when that line appears within thereact-pdf/dist/esm/entry.vite.js
file itself. Would be great to avoid duplicating this logic/dependency myself if possible! Thanks for the great library and for adding Vite support directly!Steps to reproduce
react-pdf
v6import { Document, Page } from "react-pdf/dist/esm/entry.vite";
to component fileExpected behavior
Successfully imports
react-pdf
and allows for usageActual behavior
Trying to import using the Vite entry causes the following error:
Additional information
No response
Environment
The text was updated successfully, but these errors were encountered: