nextjs config_error ai_generated true

错误:插槽 '@slot' 缺少必需的 'default.tsx' 文件。请确保插槽有默认导出。

Error: The slot '@slot' is missing the required 'default.tsx' file. Ensure the slot has a default export.

ID: nextjs/parallel-route-slot-not-found

其他格式: JSON · Markdown 中文 · English
95%修复率
85%置信度
1证据数
2023-10-27首次发现

版本兼容性

版本状态引入弃用备注
Next.js 14.0.0 active
Next.js 14.1.0 active
Next.js 14.2.0 active

根因分析

app 目录中的并行路由插槽必须有一个 default.tsx 文件,以便在找不到匹配路由时渲染;否则 Next.js 会抛出此错误以强制回退行为。

English

A parallel route slot in the app directory must have a default.tsx file to render when no matching route is found; otherwise, Next.js throws this error to enforce fallback behavior.

generic

官方文档

https://nextjs.org/docs/app/building-your-application/routing/parallel-routes#defaultjs

解决方案

  1. Create a default.tsx file in the slot directory that exports a default component, e.g., 'export default function Default() { return null; }'
  2. Use a catch-all route like '[[...slug]]' inside the slot folder with a page.tsx that handles all unmatched paths, but still ensure default.tsx exists for the slot root.
  3. If the slot is not needed, remove all references to it from layout.tsx and delete the slot folder.

无效尝试

常见但无效的做法:

  1. 70% 失败

    Layout.tsx is used for shared layouts, not as a fallback render for unmatched routes; the slot still needs default.tsx.

  2. 90% 失败

    Removing the slot breaks the parallel route structure; use default.tsx to keep the slot functional.

  3. 80% 失败

    Page.tsx only works for the root segment of the slot; default.tsx is specifically required for fallback rendering.