I cant use package in Nextjs 14
IkboljonMe opened this issue · comments
Before you start - checklist
- I followed instructions in documentation written for my React-PDF version
- I have checked if this bug is not already reported
- I have checked if an issue is not listed in Known issues
- If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo
Description
I followed exact steps. It is working in react app, but in Next.js it is not.
I used older version like x5, it is the same. In console, it is saying "Content-Security-Policy: The page’s settings blocked the loading of a resource at http://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.12.313/pdf.worker.min.js (“script-src”). page.js line 2548 > eval:694:48"
I use older version and the cnd link is
pdfjs.GlobalWorkerOptions.workerSrc =
//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.js`
But if I use newer version, I cant even set fake web worker. If I use new urlParam , it is throwing url.funtion type error. I dont know what to do, I am stucked in this problem last two day. I dont know this is bug or not. Thank you in advance
Steps to reproduce
I have blog project. I cant set up react-pdf in my repo
Expected behavior
It should not be so problematic as in react app.
Actual behavior
Loading failed for the <script> with source “http://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.12.313/pdf.worker.min.js”. resume:1:1
Content-Security-Policy: The page’s settings blocked the loading of a resource at http://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.12.313/pdf.worker.min.js (“script-src”).
Additional information
No response
Environment
- **Browser **firefox:
- React version18.2.0:
- **React-PDF version **5.7.1:
- Webpack version (if applicable): "@svgr/webpack": "^8.0.1",
Well the message is pretty clear, the workerSrc URL you specified is blocked by Content Security Policy you have. The issue is not related to React-PDF itself. Try loading the worker file from your domain.