@react-pdf/renderer crashes when used via external package in Next.js App Router (monorepo)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- next.js, react, typescript
Research direction
Reproduce the failure using the monorepo structure in packages/pdf/components.ts and apps/web/app/api/pdf/route.tsx, then compare dependency resolution with the working direct import. Start at renderToStream and inspect how the external package path differs; done means PDF generation succeeds through @repo/pdf without the runtime error.
Written by the indexing model from the issue text.
Description
When using @react-pdf/renderer in a Next.js App Router project via an external package (e.g. from a monorepo), PDF generation fails at runtime.
However, the same code works correctly if @react-pdf/renderer is installed directly in the Next.js application.
TypeError: Cannot read properties of undefined (reading 'S')
Thrown during renderToStream.
Environment
• Next.js: 15 (App Router)
• React: 19
• Node.js: 22
• Monorepo: Turborepo
• Package manager: pnpm
• @react-pdf/renderer: 4.3.2
Project structure
apps/
web/ ← Next.js App Router app
packages/
pdf/ ← custom package wrapping @react-pdf/renderer
packages/pdf exports React components based on @react-pdf/renderer:
// packages/pdf/components.ts
export { Document, Page, Text } from "@react-pdf/renderer";
❌ Failing case (renderer used via external package)
// apps/web/app/api/pdf/route.tsx
import { Document, Page, Text } from "@repo/pdf/components";
import { renderToStream } from "@repo/pdf/server";
export async function GET() {
const stream = await renderToStream(
<Document>
<Page>
<Text>Hello</Text>
</Page>
</Document>
);
return new Response(stream);
}
Result:
TypeError: Cannot read properties of undefined (reading 'S')
✅ Working case (renderer installed in app)
// apps/web/app/api/pdf/route.tsx
import { Document, Page, Text, renderToStream } from "@react-pdf/renderer";
export async function GET() {
const stream = await renderToStream(
<Document>
<Page>
<Text>Hello</Text>
</Page>
</Document>
);
return new Response(stream);
}
✅ Works without errors.
Key observation
• JSX, runtime, and code are identical
• Only difference:
• ❌ @react-pdf/renderer resolved from external package
• ✅ @react-pdf/renderer resolved from Next.js app itself
This indicates a possible issue with:
• multiple React renderers / reconciler instances
• module resolution in monorepos
• assumptions inside @react-pdf/renderer about React element identity
• interaction with Next.js App Router (RSC)
- Dominant language
- TypeScript
- Stars
- 16.8k
- Forks
- 1.3k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from diegomura/react-pdf
-
@react-pdf/font: published types import fontkit, but @types/fontkit is only a devDependencyPossibly taken @iliev-blnk claimed this 11 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Unable to set flexShrink to 0Possibly taken @adarshsm claimed this 10 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
@react-pdf/hyphenate: import-only exports map throws ERR_PACKAGE_PATH_NOT_EXPORTED in require-condition resolvers (every tsx script loading renderer >= 4.7 crashes)Possibly taken @cruzdanilo claimed this 39 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
diegomura/react-pdf#3551 · 2 reactions ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
diegomura/react-pdf#3606 · 3 reactions ·
Maintainers usually reply within 1 day
All issues in diegomura/react-pdf
Similar issues
-
🐛 bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
LibreChat-AI/LibreChat#17733 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
TypeStrong/typedoc#3150 ·
-
accessibility bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Normalize image-source MIME types before SVG dispatchPossibly taken @HarsH-1877 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
tscircuit/image-utils#58 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 74/100
Maintainers usually reply within 2 days