diegomura/react-pdf

<Image /> throws error when using in NextJS with swcMinify

Open

Aperta il 26 ott 2022

Vedi su GitHub
 (5 commenti) (0 reazioni) (0 assegnatari)JavaScript (13.687 star) (1116 fork)batch import
help wanted

Descrizione

Describe the bug I'm using react-pdf with nextjs (v12). When running in dev mode everything works as expected. When building the app for production with swcMinfiy: true in next.config.js I'm getting the following error on the component

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'width')
    at drawImage (_app-4582e1627b46c737.js:115:440420)
    at renderImage (_app-4582e1627b46c737.js:115:440829)
    at renderNode (_app-4582e1627b46c737.js:115:452973)
    at d (_app-4582e1627b46c737.js:115:452461)
    at Array.forEach (<anonymous>)
    at renderChildren (_app-4582e1627b46c737.js:115:452482)
    at renderNode (_app-4582e1627b46c737.js:115:452985)
    at d (_app-4582e1627b46c737.js:115:452461)
    at Array.forEach (<anonymous>)
    at renderChildren (_app-4582e1627b46c737.js:115:452482)

Using swcMinify: false it works as expected. But swc is considered best practice/ stable and is on per default starting Nextjs v13. So leaving it off can't be the solution.

To Reproduce as described above

Expected behavior Should not throw error

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS M1
  • Browser: Chrome
  • Nextjs v12
  • React v18
  • React-pdf v.3.0.0

Guida contributor