nextjs module_error ai_generated true

错误:动态导入 'X' 失败:模块 'Y' 不包含命名导出 'Z'。

Error: Dynamic import of 'X' failed: Module 'Y' does not contain a named export 'Z'.

ID: nextjs/dynamic-import-named-export-not-found

其他格式: JSON · Markdown 中文 · English
90%修复率
87%置信度
1证据数
2023-11-05首次发现

版本兼容性

版本状态引入弃用备注
Next.js 13.5 active
Next.js 14.0 active
Next.js 14.2 active
Next.js 15.0 active

根因分析

使用 `next/dynamic` 或 `import()` 的动态导入指定了一个在导入模块中不存在的命名导出(例如 `{ MyComponent }`)。这通常发生在模块导出默认导出但没有该名称的命名导出,或者导出名称拼写错误时。

English

A dynamic import using `next/dynamic` or `import()` specifies a named export (e.g., `{ MyComponent }`) that does not exist in the imported module. This often happens when the module exports a default export but no named export with that name, or the export name is misspelled.

generic

官方文档

https://nextjs.org/docs/app/building-your-application/optimizing/lazy-loading

解决方案

  1. 更正命名导出名称以匹配模块中的实际导出。检查模块文件以获得确切的导出名称。
  2. 如果模块导出默认导出,则使用默认导入而不指定命名导出。
  3. 如果模块目前只有默认导出,则向模块添加命名导出。将默认导出重新导出为命名导出。

无效尝试

常见但无效的做法:

  1. 85% 失败

    The 'use client' directive does not add or change exports. If the named export does not exist, the import still fails. The issue is in the export definition, not the runtime environment.

  2. 90% 失败

    The error occurs at build time or during module resolution; a try-catch in runtime code does not prevent the initial load failure. The component will not render.

  3. 70% 失败

    If the module only has a named export, a default import will result in `undefined`. The component will not render correctly, though the error may change.