react-pdf: v3.3.6 causes `TypeError: layoutEngine is not a function` in @react-pdf/renderer when using Next.js
Describe the bug
After upgrading from v3.3.5 to v3.3.6, my Next.js app’s react-pdf server-side generations are failing with:
TypeError: layoutEngine is not a function
at Object.<anonymous> (/vercel/path0/node_modules/@react-pdf/layout/lib/index.cjs:308:16)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at Module.require (node:internal/modules/cjs/loader:1115:19)
at mod.require (/vercel/path0/node_modules/next/dist/server/require-hook.js:65:28)
at require (node:internal/modules/helpers:130:18)
at Object.<anonymous> (/vercel/path0/node_modules/@react-pdf/renderer/lib/react-pdf.cjs:14:22)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
Rolling back to v3.3.5 makes the issue go away.
To Reproduce
Minimal repro available here: https://stackblitz.com/edit/stackblitz-starters-rxmqpt?file=app%2Fapi%2Fbuild-pdf%2FMyDocument.tsx
Expected behavior
react-pdf should not crash.
Screenshots
Desktop (please complete the following information):
- OS: All
- Browser: Chrome
- React-pdf version: v3.3.6
About this issue
- Original URL
- State: closed
- Created 5 months ago
- Reactions: 5
- Comments: 24 (4 by maintainers)
Commits related to this issue
- fix: fix CJS compatibility Closes #2602 Closes #2603 — committed to wojtekmaj/diegomura-react-pdf by wojtekmaj 5 months ago
- fix: fix CJS compatibility Closes #2602 Closes #2603 — committed to wojtekmaj/diegomura-react-pdf by wojtekmaj 5 months ago
- fix: CJS compatibility (#2605) Closes #2602 Closes #2603 — committed to diegomura/react-pdf by wojtekmaj 5 months ago
- chore: add basic E2E tests This proposal adds E2E tests. It runs these tests on Node.js 18, 20, and 21 (so just like unit tests), in CJS and ESM mode. Each test creates a stupid simple and compares ... — committed to wojtekmaj/diegomura-react-pdf by wojtekmaj 5 months ago
- fix: CJS compatibility (#2605) Closes #2602 Closes #2603 — committed to mskec/react-pdf by wojtekmaj 5 months ago
Will take a look today
If you have issues even after downgrading, downgrade
@react-pdf/rendererto3.3.5and override@react-pdf/layout’s version to3.10.4in yourpackage.json.pnpm:
The error states clearly that
layoutEngineis a function in@react-pdf/layoutlibrary, a direct dependency of@react-pdf/renderer. Unfortunately in@react-pdf/renderer’spackage.jsonthere is a caret (^) symbol next to the versions of its dependencies. That means package managers will try to install the newest version of its dependencies, including faulty@react-pdf/layout, regardless of which version of@react-pdf/rendereryou install.And this is why you should always pin your dependencies.
@wojtekmaj Thanks for your help, is this issue fixed ?
I get the same error using the latest version also on Next.js, but doing the following https://github.com/diegomura/react-pdf/issues/2603#issuecomment-1928973440 fixed the issue for me!
I have a strong suspicion that it is my fault (specifically, in my PR #2594).
Before:
after:
It must have something to do with output.interop Rollup option.
I just updated using ncu (which updated all the version numbers) and I started getting this error. I am not a fan of “rolling back”, but I will try it for now. Any update on this issue?
+1
Same error with node and express project