svelte-pdfjs icon indicating copy to clipboard operation
svelte-pdfjs copied to clipboard

update deps, only load and render in browser

Open gtm-nayan opened this issue 2 years ago • 2 comments
trafficstars

closes #14 closes #15

@s3812497 It can't use the $app modules from Kit, I had to change it to esm-env. There were some overdue changes I had to make to the repo as well so I created a separate PR. Can you try out the 0.7.0@next version and let me know if it works as you intended?

There are a few breaking changes, the set_pdfjs_context function is now exported from svelte-pdfjs/vite instead of svelte-pdfjs/utils/vite and deep imports are restricted.

gtm-nayan avatar May 10 '23 04:05 gtm-nayan

Thanks for this. Unfortunately, I can still only occasionally reproduce it. I'm not sure if it's my own code, but from the cloudflare logs I get this error: TypeError: Cannot read properties of undefined (reading 'includes'), which is really strange since both my code and svelte-pdfjs doesn't even reference the property includes.

teemingc avatar May 10 '23 11:05 teemingc

Hmm, that's weird, I'll put out a v0.6 with minimal changes then, hopefully that should help you narrow it down whether it's coming from pdf.js, svelte-pdfjs or somewhere else.

gtm-nayan avatar May 10 '23 13:05 gtm-nayan

This gives me:

[vite] Internal server error: Failed to resolve entry for package "svelte-pdfjs". The package may have incorrect main/module/exports specified in its package.json.

I did change svelte-pdfjs/utils/vite to svelte-pdfjs/vite per the export; this is from the plain svelte-pdfjs import (Document, Page).

OJFord avatar May 10 '24 20:05 OJFord

@OJFord do you mean with this branch specifically? Did you run the package command so that dist is created first?

gtm-nayan avatar May 11 '24 00:05 gtm-nayan

This branch yes, I noticed the deferral of getDocument and thought it might fix #18.

I did not run package to create the dist dir though! I noticed it didn't exist, but just put it down to my js inexperience and figured it was some kind of magic, especially when the same error about svelte-pdfjs/utils/vite went away just by matching the export name.

Thanks, I'll try again tomorrow (on mobile atm).

OJFord avatar May 11 '24 02:05 OJFord

Thanks for that pointer - works ok as long as I use pdfjs-dist v3 (not v4), by which I mean I get the same error as on master:

[Error] Unhandled Promise Rejection: TypeError: getDocument is not a function. (In 'getDocument({ url: file, worker, ...loadOptions })', 'getDocument' is undefined) (anonymous function) (svelte-pdfjs.js:144)

but that's clearly not an issue here, I'd just hoped it might be the solution.

(NB if I add pdfjs-dist to vite's optimizeDeps.exclude then I instead get:

[Error] [HMR][Svelte] – "Unrecoverable HMR error in <PdfAttachmentViewer>: next update will trigger a full reload" logError (proxy.js:15) [Error] Unhandled Promise Rejection: Error: this={...} of svelte:component should specify a Svelte component. flush (chunk-KQS2SRXE.js:1318)

but honestly I'm not sure if that's progress or not.)

OJFord avatar May 11 '24 18:05 OJFord