Element type is invalid: expected a string or a class/function but got: undefined
Last verified:
The fix
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. The JSX tag's value is undefined. Match the import to the export, or fix the name in the tag.
- 1
Read got: undefined or got: object
undefinedmeans the tag's identifier has no value.objectmeans you rendered a module namespace or a component map, not a component. Open the file named in the stack and find the uppercase tag on that line. - 2
Make the import match the export
No braces for
export default. Braces forexport function. Change one side. If the file only has a default and the call site wants a named import, re-export it once. Do not add both a default and a named export of two different components to silence every import.import Button from "./button"; export default function Button() { return <button type="button">Save</button>; } - 3
Render the component, not the module
import * as Button from './button'then<Button />passes the module object. Import the function, or render the property that is the function (Button.Button) only if that property exists. A lowercase tag such as<button>is a DOM element and is not this error. - 4
Break a cycle if the export is already correct
If
Buttonis exported and the import style matches, and it is stillundefinedat render, this file and another import each other. Move the shared component to a third file that imports neither. Do not add a bundler alias, and do not default the import to an empty component.
Why it happens
React throws 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. The tag in JSX evaluated to undefined. A check the render never reached is not this error.
export default function Button is a default export. import { Button } asks for a named one and gets undefined, and the page still loads if the bundler did not reject it. The reverse, import Button from './button' against export function Button, does the same. import * as Button is a module object, and <Button /> then says got: object. A typo in the tag, <Buton /> when the import is Button, is the same undefined. If the export line is already the right shape and the value is still undefined, the two files import each other, so the binding is not initialized yet.
Vite's The requested module does not provide an export named and Next's is not exported fire earlier, at the import. This page is the runtime throw, after a value of undefined or a module object reached JSX. Follow the bundler message when you have it. Do not add a second component to satisfy this throw.
The next error you'll probably hit
Once this is fixed, the usual follow-up is The requested module does not provide an export named. The file loaded, and the name you imported is not one of its exports. Vite reports a SyntaxError in the browser. Next.js says the name is not exported, or that the export does not exist in the target module.
Prompt to paste back into your AI tool
Paste this above the error.
React throws: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: <undefined or object>. The stack points at <file> and this JSX: <paste the JSX line and the import> Do not create a new component with the missing name. Do not add export default and a named export of different components just to cover both import styles. Do not edit node_modules. Do not replace the tag with a <div> to hide it. 1. Quote the export line of the file being rendered. 2. Change the import to match: no braces for default, braces for named. If the value is a module namespace object, import the function instead of import *. 3. If the export already matches and the value is still undefined, name the import cycle and move the shared component out. Do not alias it. 4. If the bundler already said the module does not provide that export, follow that fix and do not also rewrite the component.
Common questions
+The bundler already said the module does not provide an export named Button. Is this the same bug?
The import is the bug, and the bundler caught it first. Fix that mismatch. This page is the runtime throw when JSX received undefined or a module object and the bundler did not stop the page.
+It says got: object. What did I render?
A module namespace from import * as, or some other object, in a JSX tag. Import the function and render that. An object in children, not in the tag, is Objects are not valid as a React child.
+The component works in one file and throws in another. Why?
The failing file imports it the other way, or the two files import each other and this one runs before the export is initialized. Match the export, or break the cycle.
Related errors
- The requested module does not provide an export namedThe file loaded, and the name you imported is not one of its exports. Vite reports a SyntaxError in the browser. Next.js says the name is not exported, or that the export does not exist in the target module.CursorLovableBoltViteReactOct 27, 2026
- Module not found: Can't resolveModule not found: Can't resolve means the import path or package is not on disk, often after an AI edit. Fix the path or install the package, then restart.CursorLovableBoltTypeScriptNext.jsOct 14, 2026
- Can't resolve '@/components/ui/button'Can't resolve '@/components/ui/button': the v0 snippet expects shadcn files you do not have. Add those files or drop the import. In Vite, remove next/link.v0CursorBoltNext.jsReactOct 14, 2026
- Each child in a list should have a unique "key" propEach child in a list should have a unique "key" prop. Put a stable id on the element returned from map. Do not use Math.random(), and do not use the array index when the list can reorder.CursorLovableBoltReactNext.jsOct 27, 2026