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

Compile Error in Sveltekit #21

Closed ralphwest1 closed 2 years ago

ralphwest1 commented 2 years ago

When I try to add to SvelteKit v1.0.0-next.230, I get the below error:

svelte-pdf doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.

Here is the implementation:

<script>
  import { onMount } from "svelte";
  let PdfViewer;

  onMount(async () => {
    const module = await import("svelte-pdf");
    PdfViewer = module.default;
  });
</script>

<svelte:component this={PdfViewer} url="YOUR-PDF-URL"/>

Please advise if there is something I can change to make it work it SvelteKit?

raymondboswel commented 2 years ago

I had to change the following line in PdfViewer.svelte: import pdfjsWorker from "pdfjs-dist/build/pdf.worker.entry"; to import "pdfjs-dist/build/pdf.worker.entry"; I only have the changes in a local copy of the project, but perhaps worth a shot. My project isn't using SvelteKit, but is using Vite.

vinodnimbalkar commented 2 years ago

Hi, @ralphwest1 Please try with the latest svelte-pdf v.1.0.10, fixed error : it doesn't have "type": "module" or an .mjs extension for the entry point

webdagger commented 2 years ago

@vinodnimbalkar This can be closed too?