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
Have a 504 error when getting pdf.worker.js
using vite entry
#1377
Comments
Having the same issue Couldn't get it to work. |
Tried using it with vite 4 and got the same error. 😞 |
When I set an
Looking in the N.B. I've not included |
请问解决了吗? |
Don't use import { Document, Page } from 'react-pdf';
import * as pdfjs from 'pdfjs-dist/build/pdf';
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
'pdfjs-dist/build/pdf.worker.js',
import.meta.url
); |
Indeed it appears that because of vitejs/vite#10839 Vite entry file does not behave correctly. If you guys have any idea how we could possibly implement this to make it work out of the box again, I'd be very grateful. |
Thanks @idaibin , while that didn't quite work for me it did lead me to implement one of the other import { Document, Page, pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.js`; which works both when running in I suspect that the |
@idaibin thanks, it works for me. First, my My final code using typescript: import { useState } from 'react'
import { Document, Page } from 'react-pdf'
import * as pdfjs from 'pdfjs-dist'
import type { DocumentProps } from 'react-pdf'
const src = new URL('pdfjs-dist/build/pdf.worker.js', import.meta.url)
pdfjs.GlobalWorkerOptions.workerSrc = src.toString() |
@Gu-Miao your solution is now actually the recommended one in v7 😅 See README for details. |
@Gu-Miao did you manage to make it work without having to explicitly add So far I've tried to add |
Before you start - checklist
Description
I create a simple demo, but it can't work. I use pnpm, vite@4, typescript.
My code:
I get a 504 error when getting the
pdf.worker.js
:In the
.vite
dir, the bundle is:I also tried this: #1148 (comment). But it's not good for me.
By the way, the entry path in README is outdate. It's not
index.vite
, it'sentry.vite
now.Steps to reproduce
A minimal reproduction is here: https://github.com/Gu-Miao/react-pdf-test
Expected behavior
Demo works fun
Actual behavior
Get a 504 error when getting
pdf.worker.js
Additional information
No response
Environment
The text was updated successfully, but these errors were encountered: