react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

RuntimeError: Refused to compile or instantiate WebAssembly module because 'unsafe-eval'

Open paul-gansca opened this issue 1 year ago • 6 comments

Describe the bug image

I have just migrated from CRA to Vite 5.2.0 and as I was testing my app for any issues caused by this I find that I can no longer use @react-pdf/renderer (specifically <PDFDownloadLink />) to create a PDF because of a CSP issue. It still works if I add the unsafe-eval to the CSP string but I'm sure there has to be a better way. I'm also curious as to why it was working before.

Using ASP.NET on the BE with Dotnet 6.

To Reproduce

Running the client app on it's own doesn't throw any errors.

Running the app through the port which then has a websocket to connect to my server is when I'm getting the error.

Previously when using CRA this was not an issue.

I'm wondering if there is some extra config I need to do to handle stuff in VITE which may have been automatically done by CRA.

I'm using "@react-pdf/renderer": "^3.2.0", "vite": "^5.2.0",

On loading the page where I use <PDFDownloadLink /> component I get the error in the screenshot above.

Expected behavior I'm hoping to get it working as it was with CRA without having to use 'unsafe-eval'

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Chrome
  • React-pdf version 3.2.0

I've seen this issue mentioned in this thread but didn't seem like it was resolved: https://github.com/diegomura/react-pdf/issues/510

paul-gansca avatar Jul 11 '24 14:07 paul-gansca

+1. am facing this issue too!

prasanthkumaar avatar Aug 05 '24 09:08 prasanthkumaar

+1. am facing this issue too!

I figured it out mate, it's about enforcing a very specific set of resolutions (sub dependency package versions)

@react-pdf/[email protected] @react-pdf/[email protected]

paul-gansca avatar Aug 12 '24 06:08 paul-gansca

cool! thanks for figuring it out @paul-gansca 👍 setting those specific resolutions fixed it for me as well

prasanthkumaar avatar Aug 12 '24 08:08 prasanthkumaar

+1. am facing this issue too!

I figured it out mate, it's about enforcing a very specific set of resolutions (sub dependency package versions)

@react-pdf/[email protected] @react-pdf/[email protected]

I am still facing the issue, tried these versions and still having the issue.

anyone have any idea?

ashatat avatar Aug 15 '24 12:08 ashatat

+1. am facing this issue too!

I figured it out mate, it's about enforcing a very specific set of resolutions (sub dependency package versions) @react-pdf/[email protected] @react-pdf/[email protected]

I am still facing the issue, tried these versions and still having the issue.

anyone have any idea?

Have you checked with "npm ls" that you indeed have these versions?

I was only able to enforce the the sub-dependency version using yarn btw.

paul-gansca avatar Aug 15 '24 14:08 paul-gansca

@paul-gansca You were right, it wasn't getting the correct packages, I had to roll back yarn.lock to and add it in the "resolutions" and it worked Thank you very much 🙏

ashatat avatar Aug 15 '24 15:08 ashatat

any news about this? i continue to have this error....

buzzo123 avatar Dec 11 '24 13:12 buzzo123

Good morning,

I tried to apply the "resolution" solution, but today it doesn't seem to work anymore.

Has anyone of you managed to solve the problem? Thank you in advance

RiccardoRiggi avatar Jan 21 '25 10:01 RiccardoRiggi