diegomura / react-pdf

📄 Create PDF files using React
https://react-pdf.org
MIT License
14.9k stars 1.18k forks source link

Module not found: Can't resolve 'yoga-layout' with React 16.14.0 and Node 21 #2650

Open koranra opened 8 months ago

koranra commented 8 months ago

Describe the bug Trying to import the library and generate a PDF and am running into issues - Module not found: Can't resolve 'yoga-layout' with React 16.14.0 and Node 21

To Reproduce attached sample code with a simple example. I followed all the things mentioned in this thread - https://github.com/diegomura/react-pdf/issues/2499. It works when I use *renderer v3.1.14 and layout v3.6.3**, But it generates a empty pdf. So its breaking with that approach as well.

sample-app.zip

any help would be highly appreciated.

andrey-prokhorov commented 8 months ago

The same problem with React 18.2 and Node v20.10

koranra commented 8 months ago

@andrey-prokhorov it works for me if I upgrade to react 18 with node 21. But my app is on React 16.14 and thats where its causing the issue.

jgo80 commented 8 months ago

I encounter the issue client side, packaging my app with Expo/Metro Bundler with the following error:

Unable to resolve "yoga-layout" from "node_modules/@react-pdf/layout/lib/index.cjs"

Node v21.6.2 React 18.2.0

PelosiTech commented 8 months ago

@jgo80 @koranra @andrey-prokhorov @koranra

Add this in your package.json

"resolutions": { "@react-pdf/layout": "3.6.4", "@react-pdf/textkit": "4.3.0", "@react-pdf/image": "2.2.2", "@react-pdf/pdfkit": "3.1.2" }

ytreister commented 8 months ago

I fixed by adding to my package.json:

    "overrides": {
        "@react-pdf/layout": "3.6.4",
        "@react-pdf/textkit": "4.3.0",
        "@react-pdf/image": "2.2.2",
        "@react-pdf/pdfkit": "3.1.2"
    },
wojtekmaj commented 7 months ago

Duplicate of #2499?