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

Could not read from file: ...pdf.worker.min.js #47

Closed advancedlogic closed 1 year ago

advancedlogic commented 1 year ago

With the default example I see the pdf for 1 second and then I have error 504 (because it cannot find the file and timeouts) and I keep having this issue:

`✘ [ERROR] Could not read from file: /Users/user/Projects/Git/myproject/static/ui/node_modules/svelte-pdf/node_modules/pdfjs-dist/build/pdf.worker.min.js?url

node_modules/svelte-pdf/PdfViewer.svelte:45:24:
  45 │ ...rt pdfjsWorker from "pdfjs-dist/build/pdf.worker.min.js?url";`

I am using last version of Svelte/SvelteKit/Vite together with Tailwinds

Gildedter commented 1 year ago

Having the same issue, I took a look at #27, which says its fixed

my error looks likes this:

> npm run dev                                                                                                                                                                   > codeignitervite-svelte@0.0.0 dev                                                      > vite                                                                                  
        suggestion: ''
      },
      notes: [],
      pluginName: '',
      text: 'Could not read from file: C:\\PROJECT_DIR\\node_modules\\pdfjs-dist\\build\\pdf.worker.min.js?url'
    }
  ],  warnings: []
}

Node.js v18.12.1
eddyvinsensius commented 1 year ago

does anyone know howto resolve this? , i'm having the same issue with just the default example and current version of sveltekit .. thanks.

vinodnimbalkar commented 1 year ago

Hi @eddyvinsensius , Please try to reproduce the same bug on stackblitz

ricardoalcantara commented 1 year ago

Hi, even the example doesn't work for me.

I am using Windows 10

pnpm --version 7.25.1

node --version v18.12.1

C:\Projects\nodejs\svelte-pdf\example〉pnpm run dev                                                                                                                                          02/10/2023 12:58:14

> svelte-app@0.0.0 dev C:\Projects\nodejs\svelte-pdf\example
> vite

Forced re-optimization of dependencies
Port 5173 is in use, trying another one...

  VITE v3.2.5  ready in 655 ms

  ➜  Local:   http://localhost:5174/
  ➜  Network: use --host to expose
✘ [ERROR] Could not read from file: C:\Projects\nodejs\svelte-pdf\example\node_modules\.pnpm\pdfjs-dist@3.3.122\node_modules\pdfjs-dist\build\pdf.worker.min.js?url

    node_modules/.pnpm/svelte-pdf@1.0.16/node_modules/svelte-pdf/PdfViewer.svelte:39:24:
      39 │ import pdfjsWorker from "pdfjs-dist/build/pdf.worker.min.js?url";
         ╵                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

12:58:19 [vite-plugin-svelte] prebundle libraries in progress ...
C:\Projects\nodejs\svelte-pdf\example\node_modules\.pnpm\esbuild@0.15.18\node_modules\esbuild\lib\main.js:1575
  let error = new Error(`${text}${summary}`);
              ^

Error: Build failed with 1 error:
node_modules/.pnpm/svelte-pdf@1.0.16/node_modules/svelte-pdf/PdfViewer.svelte:39:24: ERROR: Could not read from file: C:\Projects\nodejs\svelte-pdf\example\node_modules\.pnpm\pdfjs-dist@3.3.122\node_modules\pdfjs-dist\build\pdf.worker.min.js?url
    at failureErrorWithLog (C:\Projects\nodejs\svelte-pdf\example\node_modules\.pnpm\esbuild@0.15.18\node_modules\esbuild\lib\main.js:1575:15)
    at C:\Projects\nodejs\svelte-pdf\example\node_modules\.pnpm\esbuild@0.15.18\node_modules\esbuild\lib\main.js:1033:28
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errors: [
    {
      detail: undefined,
      id: '',
      location: {
        column: 24,
        file: 'node_modules/.pnpm/svelte-pdf@1.0.16/node_modules/svelte-pdf/PdfViewer.svelte',
        length: 40,
        line: 39,
        lineText: 'import pdfjsWorker from "pdfjs-dist/build/pdf.worker.min.js?url";',
        namespace: '',
        suggestion: ''
      },
      notes: [],
      pluginName: '',
      text: 'Could not read from file: C:\\Projects\\nodejs\\svelte-pdf\\example\\node_modules\\.pnpm\\pdfjs-dist@3.3.122\\node_modules\\pdfjs-dist\\build\\pdf.worker.min.js?url'
    }
  ],
  warnings: []
}

Node.js v18.12.1
 ELIFECYCLE  Command failed with exit code 1.
vinodnimbalkar commented 1 year ago

look like an issue with vite, please ref: https://github.com/vitejs/vite/issues/10838

antoineMagentine commented 1 year ago

Hi, I was looking at this because I had the same issue. react-pdf had the same problem and they fixed it by removing the ?url at the end of the pdfJsWorker import url (not supported by Vite). Maybe that'll help you, here's how they fixed it : https://github.com/wojtekmaj/react-pdf/compare/v6.0.1...v6.0.2

It worked for me :)

vinodnimbalkar commented 1 year ago

Thanks @antoineMagentine This issue was fixed by https://github.com/vinodnimbalkar/svelte-pdf/pull/50 so closing it.