Error: Dynamic import of 'X' failed: Module 'Y' does not contain a named export 'Z'.
ID: nextjs/dynamic-import-named-export-not-found
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Next.js 13.5 | active | — | — | — |
| Next.js 14.0 | active | — | — | — |
| Next.js 14.2 | active | — | — | — |
| Next.js 15.0 | active | — | — | — |
Root Cause
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中文
使用 `next/dynamic` 或 `import()` 的动态导入指定了一个在导入模块中不存在的命名导出(例如 `{ MyComponent }`)。这通常发生在模块导出默认导出但没有该名称的命名导出,或者导出名称拼写错误时。
Official Documentation
https://nextjs.org/docs/app/building-your-application/optimizing/lazy-loadingWorkarounds
-
95% success Correct the named export name to match the actual export in the module. Check the module file for the exact export name.
Correct the named export name to match the actual export in the module. Check the module file for the exact export name.
-
90% success If the module exports a default export, use a default import without specifying a named export.
If the module exports a default export, use a default import without specifying a named export.
-
85% success Add a named export to the module if it currently only has a default export. Re-export the default as a named export.
Add a named export to the module if it currently only has a default export. Re-export the default as a named export.
中文步骤
更正命名导出名称以匹配模块中的实际导出。检查模块文件以获得确切的导出名称。
如果模块导出默认导出,则使用默认导入而不指定命名导出。
如果模块目前只有默认导出,则向模块添加命名导出。将默认导出重新导出为命名导出。
Dead Ends
Common approaches that don't work:
-
85% fail
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.
-
90% fail
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.
-
70% fail
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.