Warning: React.createElement: type is invalid -- expected a string or a function/component but got: undefined
Error message
Element type is invalid: expected a string or a function/component but got: undefined.
Quick summary
You rendered `<SomeComponent />` but `SomeComponent` is undefined, often due to a default/named export mismatch.
Why this happens
Imported a named export as default or vice versa
The component file doesn't export anything
Circular import issue
Dynamic import returned undefined
Minimal example
// Component uses named export
export function Header() { return <h1>Hi</h1>; }
// But imported as default
import Header from "./Header"; // undefined!// Use named import
import { Header } from "./Header";The file uses a named export but the import uses default syntax, resulting in undefined. Matching the import to the export fixes it.
How to diagnose
Check the import statement and the export in the component file
Log the component before rendering:
console.log(SomeComponent)Verify the export type (default vs named) matches the import
How to fix
Fix the import to match the export:
import { Component }for named,import Componentfor defaultEnsure the component file has the correct export statement
Resolve circular imports by restructuring dependencies
How to prevent
Be consistent with default vs named exports
Use IDE auto-import to avoid mismatches
Related Resources
Related Glossary
Related Lessons
- Components
Learn component imports and exports.