mozilla / pdf.js

PDF Reader in JavaScript
https://mozilla.github.io/pdf.js/
Apache License 2.0
47.2k stars 9.82k forks source link

When importing pdf_viewer.css I get "Module not found: Error: Can't resolve './images/altText_add.svg'" #18114

Closed lfoppiano closed 1 month ago

lfoppiano commented 1 month ago

I'm using PDF.js programmatically in a component for streamlit, which uses vue.js as js framework. I've imported the CSS pdfjs-dist/web/pdf_viewer.css but it seems there are references to svg images that do not exist:

    --alt-text-add-image: url(images/altText_add.svg);
    --alt-text-done-image: url(images/altText_done.svg);

Commenting these lines seems to solve the problem (not sure if it's creating new ones).

Configuration:

Steps to reproduce the problem:

  1. import pdfjs-dist/web/pdf_viewer.css
  2. open the app that does that

What is the expected behavior? (add screenshot)

That it works

What went wrong? (add screenshot)

Here the build error: https://github.com/lfoppiano/streamlit-pdf-viewer/actions/runs/9135512859/job/25122945743

 error  in ./node_modules/pdfjs-dist/web/pdf_viewer.css

Syntax Error: ModuleNotFoundError: Module not found: Error: Can't resolve './images/altText_add.svg' in '/home/runner/work/streamlit-pdf-viewer/streamlit-pdf-viewer/streamlit_pdf_viewer/frontend/node_modules/pdfjs-dist/web'
Snuffleupagus commented 1 month ago

I've imported the CSS pdfjs-dist/web/pdf_viewer.css but it seems there are references to svg images that do not exist:

    --alt-text-add-image: url(images/altText_add.svg);
    --alt-text-done-image: url(images/altText_done.svg);

It looks like those files are included just fine in an up-to-date build, according to https://github.com/mozilla/pdf.js/blob/63b66b412cb3be6919c14436487c667a1597a732/gulpfile.mjs#L1119-L1126

PDF.js version: 3.11.174

That version is no longer supported, please find the latest releases at https://mozilla.github.io/pdf.js/getting_started/#download

For future reference: Please make sure to always test the latest version, since that's the only one we support, before reporting a bug or asking for help.

lfoppiano commented 1 month ago

@Snuffleupagus thanks a lot for your quick answer.

I might overlooking something here. I've deleted and re-installed all my dependencies using NPM:

These files are not there in my node_modules:

image

Also I did not see them in the same version in NPMjs:

https://www.npmjs.com/package/pdfjs-dist/v/3.11.174?activeTab=code

Any idea what I'm doing wrong?

Using version 4 is also my hope some day, I haven't managed to update from version 3 to version 4. There seems to have been several breaking changes in how the modules are loaded.

There was a pdf_worker.entry which disappers in version 4:

image

Is there an upgrade guide? I could not find it...

Snuffleupagus commented 1 month ago

These files are not there in my node_modules:

Note that they are included in https://www.npmjs.com/package/pdfjs-dist/v/4.2.67?activeTab=code, which as already mentioned is the only version that we support.

Another reason to update is that the version you're using contains a security vulnerability, see https://github.com/mozilla/pdf.js/security/advisories/GHSA-wgrm-67xf-hhpq

There was a pdf.worker.entry which disappers in version 4:

That old file caused the worker-code to be loaded on the main-thread which results in really bad performance, hence why it's removed.

lfoppiano commented 1 month ago

I'm happy to update, but do you have any documentation for that?