wojtekmaj / react-pdf

Display PDFs in your React app as easily as if they were images.
https://projects.wojtekmaj.pl/react-pdf
MIT License
9.34k stars 882 forks source link

pdfjs-dist exports .mjs file that doesnt get transpiled by babel as its within node_modules #1795

Closed reedasha closed 4 months ago

reedasha commented 4 months ago

Before you start - checklist

Description

We're importing pdfJsWorker through -

import pdfJsWorker from 'pdfjs-dist/build/pdf.worker.min.mjs'; pdfjs.GlobalWorkerOptions.workerSrc = pdfJsWorker;

When running unit test with jest, its failing as babel is not transpiling .mjs files, as node_modules folder is ignored by transformers. The issue is blocking us from testing our component that renders pdf, so we're forced to look for another pdf library

Steps to reproduce

Create a component that imports pdfJsWorker Write a test Run a test

Expected behavior

Run tests successfully without errors

Actual behavior

image

Additional information

No response

Environment

wojtekmaj commented 4 months ago

We're importing pdfJsWorker through -

import pdfJsWorker from 'pdfjs-dist/build/pdf.worker.min.mjs';

and why is that? The version of PDF.js that we're using doesn't have .mjs files. You must be either installing your own copy of PDF.js or you've misread documentation.

AndyAlkhawand commented 4 months ago

The current react-pdf version is dependent on pdfjs-dist version 3.11.174 which causes a high security vulnerability https://github.com/advisories/GHSA-wgrm-67xf-hhpq

wojtekmaj commented 4 months ago

Yep. Read more at https://github.com/wojtekmaj/react-pdf/discussions/1786