Error: An error occurred while loading the component. The lazy component must be a default export.
Error message
The lazy component must be a default export.
Quick summary
The module passed to React.lazy uses a named export but React.lazy expects a default export.
Why this happens
Component uses named export but React.lazy expects default
Forgot to add
defaultin the import:() => import('./Comp')instead of() => import('./Comp').then(m => m.Comp)
Minimal example
// Component uses named export
export function Admin() { return <div>Admin</div>; }
// React.lazy expects default
const Admin = React.lazy(() => import("./Admin")); // Error!// Use default export
export default function Admin() { return <div>Admin</div>; }
const Admin = React.lazy(() => import("./Admin"));React.lazy calls the import function and reads .default from the module. Using a default export makes this work correctly.
How to diagnose
Check the component file's export statement
Verify the React.lazy import syntax
How to fix
Change the component to use
export defaultOr map the named export:
React.lazy(() => import('./Comp').then(m => ({ default: m.Comp })))
How to prevent
Use default exports for lazy-loaded components
Or use the .then() mapping pattern for named exports
Related Resources
Related Glossary
Related Lessons
- Lazy Loading
Learn React.lazy requirements.