vinodnimbalkar / svelte-pdf

svelte-pdf provides a component for rendering PDF documents using PDF.js
https://www.npmjs.com/package/svelte-pdf
MIT License
196 stars 47 forks source link

Not able to import MJS in Astro + svelte #85

Closed lewisjr closed 1 month ago

lewisjr commented 1 month ago

Okay so i have an astro site and I just added svelte (typescript), when importing svelte-pdf as per the docs I get the following error when running yarn dev:

Error could not read from file: C:\...\node_modules\svelte-pdf\node_modules\pdfjs-dist\build\pdf.worker.js

The reason really is because pdfjs uses .mjs now and no default export, so changing it to the bottom phrase works:

pdfjs.GlobalWorkerOptions.workerSrc = new URL("pdfjs-dist/build/pdf.worker.js", import.meta.url);

In case anyone has this issue, make sure to set your svelte component in astro as follows:

<Componenet client:only="svelte" />
lewisjr commented 1 month ago

Forgot to add that I am using svelte-pdf v1.0.20

lewisjr commented 1 month ago

I think the issue is elsewhere my bad