React.lazy or next/dynamic resolves to undefined
Element type is invalid. Received a promise that resolves to: undefined. Lazy element type must resolve to a class or function.Short answer
React.lazy and next/dynamic expect the imported module to expose a component as its default export. A named export, or a default that is not a component, gives undefined, which React reports as an invalid element type. Return the named export from the import promise, or export the component as default.
Fix it fast
1Find out which cause you have
Open the file you pass to import() and see how the component is exported. Then log the module to see what keys it has.
import('./components/Chart').then((mod) => console.log(Object.keys(mod)))2Match what you see, then jump to its fix
- 1
Object.keys(mod) prints [ 'Chart' ] with no 'default'The component is a named export, but lazy wants the defaultFix - 2
Object.keys(mod) prints [ 'default' ], and the default is an object, a string or undefinedThe default export exists but is not a componentFix - 3
The component file does have the named export, but you still get undefinednext/dynamic returns the wrong key from the moduleFix
- 1
What does the error look like?
Element type is invalid. Received a promise that resolves to: undefined. Lazy element type must resolve to a class or function.
Cause 1 of 3
The component is a named export, but lazy wants the default
1Check
The React docs state that this pattern requires the lazy component to be exported as the default export. A file with export function Chart() has no default.
grep -n "export" components/Chart.tsx2Fix
Either add a default export to the component file, or map the named export to default in the load function.
// React
const Chart = lazy(() =>
import('./components/Chart').then((m) => ({ default: m.Chart }))
)
// Next.js
const Chart = dynamic(() =>
import('./components/Chart').then((mod) => mod.Chart)
)3Verify
Reload the page; the lazy component renders instead of throwing.
npm run devConfirmed by nextjs.org
Cause 2 of 3
The default export exists but is not a component
1Check
The load function must resolve to an object whose .default property is a valid React component type: a function, memo or forwardRef component. A default that is a plain object or a string fails.
import('./components/Chart').then((m) => console.log(typeof m.default))2Fix
Make the default export the component itself.
// components/Chart.tsx
export default function Chart() {
return <canvas />
}3Verify
typeof m.default now prints function.
import('./components/Chart').then((m) => console.log(typeof m.default))Confirmed by react.dev
Cause 3 of 3
next/dynamic returns the wrong key from the module
1Check
In next/dynamic the promise must return the component itself. A typo in mod.Name, or returning the whole module object, resolves to something that is not a component.
grep -rn "dynamic(" -A3 app components | grep -n "mod"2Fix
Return exactly the exported component from the then callback, with the same spelling as the export.
const Hello = dynamic(() =>
import('../components/hello').then((mod) => mod.Hello)
)3Verify
Reload the page with the component visible.
npm run devConfirmed by nextjs.org
How do I stop it coming back?
- Pick one export style per component folder (default only) so lazy imports need no mapping.
- Declare lazy components at module top level, not inside another component.
- Type the load function; TypeScript flags a module with no default.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
Upgrading to Next.js 16: middleware becomes proxy, and the other things that break
Missing Required default.js for Parallel Route
Next.js 16 renames middleware.ts to proxy.ts and its exported function to proxy.
6 causes, each with a fixWeb apps
Warning: Extra attributes from the server in the console
Text content does not match server-rendered HTML
React found attributes on an element in the server HTML that its own render did not produce.
3 causes, each with a fixWeb apps
Next.js stops with 'document is not defined' while it renders on the server
ReferenceError: document is not defined
Next.js renders your components on the server first, where there is no document.
3 causes, each with a fixWeb apps
A custom error from the server arrives at the client as a generic message
error.digest holds a hash instead of your message
Next.js hides the message of errors thrown in Server Components in production, to avoid leaking details.
3 causes, each with a fixWeb apps
useState fails in a child component in the Next.js App Router
React client hook in Server Component
In the App Router every component is a Server Component unless a file above it is marked otherwise, and Server Components cannot use state or effects.
3 causes, each with a fixWeb apps
React warns about updating one component while another renders
To locate the bad setState() call inside `Child`, follow the stack trace
React renders must be pure.
4 causes, each with a fix