-
Attach (recommended) or Link to PDF fileThe problem arises at import time, so the PDF never gets a chance to load. Web browser and its versionChrome Version 135.0.7049.85 (Official Build) (64-bit) Operating system and its versionWindows 11 PDF.js version5.1.91 Is the bug present in the latest PDF.js version?Yes Is a browser extensionNo Steps to reproduce the problemI am not sure this is a duplicate of bug 19764 as I am running inside of a REACT application. However, the symptoms are identical. The DOMMatrix class seems to be required at import time and not execution time. When I comment out the code, I can see the DOMMatrix is present when the window object becomes available. It's just that the window object is not available until after my component is executed. The question I have is - how do I keep PDFJS from requiring the DOMMatrix until execution time? For completeness, I am using typescript and my import is simply: import pdfjs from "pdfjs-dist"; Any help would be greatly appreciated. Thanks! What is the expected behavior?The PDFJS library becomes available for use within the application. What went wrong?Link to a viewerNo response Additional contextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Getting the same with Next.js |
Beta Was this translation helpful? Give feedback.
-
I am guessing this is because your react application is being server rendered (especially you @pavelsavva) and the server render runs in a node process and not in a browser context, so it cannot use the default version of pdfjs-dist but should use the legacy version. |
Beta Was this translation helpful? Give feedback.
-
In my case tests (vitest) are failing with this error after upgrade to the v5. I solved by using legacy import in the
|
Beta Was this translation helpful? Give feedback.
I'm running locally and my start is "react-router dev". I agree with @petero-dk that I am performing server-side rendering as the window object is not available at the time I was doing the import.
To resolve this, I dynamically imported the library when the component function is being executed. It looks roughly as follows: