Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

React.lazy or next/dynamic resolves to undefined

ErrorElement 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.

  • Applies to React 19, Next.js 15, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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)))
  2. 2Match what you see, then jump to its fix

    1. 1Object.keys(mod) prints [ 'Chart' ] with no 'default'The component is a named export, but lazy wants the defaultFix
    2. 2Object.keys(mod) prints [ 'default' ], and the default is an object, a string or undefinedThe default export exists but is not a componentFix
    3. 3The component file does have the named export, but you still get undefinednext/dynamic returns the wrong key from the moduleFix

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.tsx

2Fix

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 dev

Confirmed by nextjs.org

Did this fix it?

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

Did this fix it?

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 dev

Confirmed by nextjs.org

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.