React: Element type is invalid, got undefined
React received undefined where JSX needs a component: a default/named import mismatch, a circular barrel, or lazy without a default export.

Introduction & Quick Summary
Error: Element type is invalid: expected a string (for built-in components)
or a class/function (for composite components) but got: undefined. You likely
forgot to export your component from the file it's defined in, or you might
have mixed up default and named imports.React received undefined where JSX expects a component. In production builds the same crash is Minified React error #130, with no hint at all, which is why this error is worth understanding once.
The import is almost always the cause, not the component:
- Default vs named mismatch —
import Button from "./Button"againstexport function Button, or the reverse. - The file exports nothing — a missing
export default, a file that only defines a type, or a re-export barrel that loses the name. - A circular import — the module evaluates before its export exists, so the binding is
undefinedat first render. React.lazypointed at a module without a default export —lazyreadsmodule.default.- Two React copies or a version jump — a library component created by a different React instance, or an export removed in a major version.
| Symptom | Most likely cause | First check |
|---|---|---|
| Works in one file, fails after moving | Default/named import | The exporting file's export keyword |
| Fails only on first render, then works | Circular import | Import graph around the barrel file |
| Fails only for one library component | Version mismatch / renamed export | npm ls react react-dom |
| Fails only in production | Minified #130 | Reproduce in dev build |
Fails after adding a barrel index.ts | Re-export missing or circular | Barrel contents and order |
Fails inside lazy boundary | No default export | Add export default or map it |
Core Mechanics, Signatures & Reproducible Setup
JSX is a function call. <Foo /> compiles to jsx(Foo, {}), and React checks what Foo is at render time: a string for host elements ("div"), a function or class for composite components, or the special types Fragment, Suspense, Profiler. Anything else — undefined, null, a plain object, a number — triggers this error.
A failed import is the usual path to undefined. ES module semantics matter here: a missing named export is a build-time error in strict bundlers, while a missing default import silently yields undefined, which is exactly what React reports.
Reproduce the two most common shapes:
// Button.tsx
export function Button({ label }: { label: string }) {
return <button>{label}</button>;
}// App.tsx
import Button from "./Button"; // undefined: no default export
export default function App() {
return <Button label="Save" />; // Element type is invalid
}// icons.ts
export * from "./icons/arrow";
export * from "./icons/close";// palette.tsx
import { Arrow } from "./icons"; // barrel also imports palette
export function Palette() {
return <Arrow />; // may be undefined during the cycle
}The build passes in both cases with most bundlers, so the failure is a runtime render, not a compile error. That is the trap: type checking often only sees any from a loose declaration or does not catch the default import at all when esModuleInterop is on.
Key Comparison Table
| Import style | Requires in exporter | Value if mismatched |
|---|---|---|
import X from "./x" | export default X | undefined |
import { X } from "./x" | export function X / export const X | Build error in strict ESM |
import * as X from "./x" | Any named export | Namespace object |
const X = lazy(() => import("./x")) | export default | undefined on resolve |
lazy(() => import("./x").then(m => ({ default: m.X }))) | Named export | Works |
| Diagnosis | Command or check | Confirms |
|---|---|---|
| Export shape | Open the exporting file's export lines | Default vs named |
| Duplicate React | npm ls react react-dom | Two versions in the tree |
| Circular import | Bundler's circular-dependency warning | Barrel cycle |
| Lazy target | Log the resolved module | Missing default |
| Production-only | next build then next start locally | Minified #130 |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
Case 1: Default and named, fixed at the boundary
// broken
import Button from "./Button";// fixed — match the exporter
import { Button } from "./Button";If you cannot change every call site, add the default re-export in the component file:
export function Button(props: ButtonProps) { /* ... */ }
export default Button; // now both import styles workPrefer one style per project. Mixed conventions are how this error keeps coming back after a refactor.
Case 2: lazy needs a default export
const Chart = lazy(() => import("./Chart")); // Chart.tsx exports named onlylazy resolves the module and reads default. Map the named export instead:
const Chart = lazy(() =>
import("./Chart").then((m) => ({ default: m.Chart }))
);Wrap it in Suspense with a fallback, otherwise the boundary has nothing to render while the chunk loads and you get a different warning.
<Suspense fallback={<p>Loading chart…</p>}>
<Chart data={data} />
</Suspense>Case 3: A barrel file that creates a cycle
// components/index.ts
export * from "./Palette";
export * from "./icons/Arrow";// components/Palette.tsx
import { Arrow } from "./index"; // cycle: index -> Palette -> indexDuring evaluation Palette loads index, which has not finished defining Arrow yet, so the binding is undefined at module scope. Import from the concrete module inside the barrel's own subtree:
import { Arrow } from "./icons/Arrow";If a component only needs the type, use import type so the import disappears at compile time and cannot create a runtime cycle.
Case 4: Two React copies
npm ls react react-dom
# ├─ react@19.2.0
# └─ some-lib@1.4.0
# └─ react@18.3.1 deduped? no — nestedA component exported by a library built against React 18 can still render, but its internal hooks bind to a different dispatcher and behavior breaks in ways that look unrelated. Dedupe with an override:
{
"overrides": {
"react": "$react",
"react-dom": "$react-dom"
}
}For a workspace monorepo, also check that the package is not hoisted twice by pnpm with different peer resolutions.
Case 5: A component that is an object, not a function
const Card = { Header, Body }; // plain object
return <Card />; // Element type is invalidObject namespaces are not components. Destructure the piece you need, or wrap the object in a real component:
function CardShell({ children }: { children: React.ReactNode }) {
return <section className="card">{children}</section>;
}The same happens with const Field = { Text: TextField, Select } from generated form libraries; use Field.Text, not Field.
Case 6: A library's export was removed or renamed
import { Link } from "react-router"; // v7: package is react-router
import { Link } from "react-router-dom";Major upgrades change entry points (react-router-dom to react-router in v7, @mui/material subpath moves, icon packages reorganized). When one component fails and every other import in the file works, check that library's changelog before touching your own code.
npm view react-router version peerDependenciesCommon Compilation/Runtime Mistakes & Version Gotchas
- Trusting the type checker here. A default import from a CommonJS module with
esModuleInteropcompiles even when the runtime value isundefined; the error only appears at render. - Assuming
export *re-exports defaults. It does not.export { default } from "./x"is required to pass a default through a barrel. - Ignoring the production-only case.
next build+next startlocally reproduces #130 with the same stack; a dev-only fix session leaves it for users. - React 19 and
forwardRef. Components wrapped inforwardRefstill work, butrefis now a regular prop; a library that dropped the wrapper can return a different export shape. - Fast Refresh masking the cycle. A broken circular import often fixes itself on hot update and returns after a full reload; verify with a fresh server start.
- Case-insensitive filesystems.
import "./button"resolving toButton.tsxon macOS can fail asundefinedon Linux CI; keep file and import casing identical.
To compare two dependency trees after an upgrade, paste both npm ls --json outputs into the JSON formatter and diff them with the diff tool. Both make a nested duplicate obvious in seconds.
Primary references: lazy documents the default-export requirement for lazy-loaded components, and Importing and Exporting Components covers the default/named rules that produce this error.
Official references
primary documentationThe React documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit React work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related React guides
All React guidesReact 19: Support for defaultProps will be removed
React 19 ignores defaultProps on function components, so a default becomes undefined. Move defaults into the parameter list and handle null honestly.
React: Each child in a list should have a unique key prop
Keys tell React which item is which between renders. Use stable ids, avoid index keys and put the key on the mapped element, not on a wrapper.
react-hook-form with zod 4: resolver type errors after the upgrade
Zod 4 split input from output and resolvers v5 re-typed Resolver. Drop the generic, or pass all three, and the errors disappear.
React Profiler API: Measuring Render Timings and Identifying Wasted Re-Renders
actualDuration versus baseDuration, phase names that tell you who triggered a commit, and how to ship the numbers without flooding a backend.
More in React
All React guidesThe guides filed next to this one in React, in library order.