-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Unable to use ?url
, ?worker
, or new URL(…, import.meta.url)
inside 3rd party module
#10837
Comments
Related to #8261 |
#6918 looks related, but the fix that closed it doesn't seem to resolve the issue, or I don't understand something... |
?url
, ?worker
inside 3rd party module, or otherwise import another module as URL/worker inside 3rd party module?url
, ?worker
, or new URL(…, import.meta.url)
inside 3rd party module
I came to the conclusion that:
The following should be working in Vite 3.2.0 after analysing #7837 import * as pdfjs from 'pdfjs-dist/build/pdf';
pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker', import.meta.url); and yet, this results in 404 Not found response on request to What I do see, however, is this in From what I see:
|
I THINK I've managed to reproduce it here: https://github.com/wojtekmaj/vite-missing-deps-bug But what worries me is that in repro, I'm getting 504 Gateway Timeout, whereas on real app it's 404 Not found that's bugging me. In both cases, however, the resolved module URL is nowhere to be found in |
Describe the bug
I'm trying to fix an issue with first-class Vite support for React-PDF. "first-class" support means you can import React-PDF using bundler-specific entry file and all the configuration will be done for you. "all the configuration" means passing
workerSrc
orworkerPort
topdfjs
, library that renders the PDFs.workerSrc
expects an URL,workerPort
- a Worker. Either is fine.So my goal is fairly simple: from
react-pdf
, import file (either as URL or worker) frompdfjs-dist
.For Webpack 5, this works:
entry.webpack5.js
and this works:
entry.webpack5.js
For Webpack 4, this works:
entry.webpack4.js
For Parcel 2, this works:
entry.parcel2.js
Neither of these options work for Vite. Neither does what Vite docs seem to recommend:
entry.vite.js
Reproduction
https://github.com/wojtekmaj/react-pdf/tree/vite-test
Steps to reproduce
I came up with every possible combination of imports, suffixes, and techniques to pass worker to
pdfjs
. Here's the full list of techniques (if I'm missing something, let me know!)I then made an entry file out of each of 33 possibilities listed above. I pushed them to https://github.com/wojtekmaj/react-pdf/tree/vite-test branch. Then, I used
sample/vite
sub-repository as a testing site and started importing React-PDF using each entry files.1, 2, 3 - resulting in "Setting up fake worker", meaning - we didn't import the worker correctly (e.g. workerSrc was not a string).
4, 5 - stuck on loading, meaning - it probably got recognized as worker but it's not really a valid worker.
6 - "Could not read from file: /react-pdf/sample/vite/node_modules/pdfjs-dist/build/pdf.worker.js?url"
7, 8 - "Could not read from file: /react-pdf/sample/vite/node_modules/pdfjs-dist/build/pdf.worker.js?worker"
9 - resulting in "Setting up fake worker".
10 - "Could not read from file: /react-pdf/sample/vite/node_modules/pdfjs-dist/build/pdf.worker.entry.js?url"
11, 12 - "Could not read from file: /react-pdf/sample/vite/node_modules/pdfjs-dist/build/pdf.worker.entry.js?worker"
13, 14, 15 - 404 Not found
16, 17, 18 - "__require.resolve is not a function"
19, 20, 21, 22, 23, 24 - 404 Not found
25, 26, 27 - stuck on loading.
28, 29, 30 - "__require.resolve is not a function"
31, 32, 33 - stuck on loading.
System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: