#5008·nextra

Error Invalid input: expected nonoptional, received undefined → at children

Author: nomikuggCreated May 28, 2026Updated May 29, 2026
Labelsbug

After spending hours debugging this issue, I found this PR #4990 that helped me understand and fix the root cause. However, even after the fix was merged, the issue still seems to persist in some environments.

Issue

This error appears when using:

Error:

This issue is still reproducible in some environments even with:

imageimage

Root cause

Nextra's Layout component validates props using Zod:

bash
LayoutPropsSchema.safeParse(themeConfig)

However, children is destructured before validation:

bash
({ children, ...themeConfig } = props)

So children is NOT included in the object passed to Zod.

With Zod 4.4.x, missing required keys now throw BEFORE custom validation runs, resulting in:

✖ Invalid input: expected nonoptional, received undefined → at children

This is caused by stricter validation behavior in Zod 4.4 combined with Nextra's prop handling.


Temporary workaround (manual fix)

Until an official fix is fully available, the schema input must include children.

File location:

bash
node_modules/nextra-theme-docs/dist/layout.js

Change:

javascript
LayoutPropsSchema.safeParse(themeConfig)

To:

javascript
LayoutPropsSchema.safeParse({ children, ...themeConfig })

Persistent fix (recommended)

For pnpm projects, you can persist this fix using the patch workflow:

bash
pnpm add -D patch-package
pnpm patch nextra-theme-docs

Then edit

bash
dist/layout.js

Apply the same fix:

javascript
safeParse({ children, ...themeConfig })

Finally commit the patch:

bash
pnpm patch-commit

This ensures the fix survives reinstallations and CI/CD environments.

image