React was asked to render something that is not a component (it got undefined)
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.Short answer
React received something that is not a tag name or a component, most often undefined, because the import resolved to nothing. The usual causes are a default import of a named export (or the reverse), a circular import that has not finished loading, a lazy module without a default export, or a Server Component using a static member such as Menu.Item of a client component.
Fix it fast
1Find out which cause you have
The message ends with the name of the component whose render produced the bad element, and in development the stack shows the file. Open that component, look at every capitalised tag in its JSX, and print what each import really is. A tag that prints undefined is the culprit; then the causes below say why that import came back empty.
// in the file named by 'Check the render method of ...', next to the imports import * as Buttons from './Button' import Card from './Card' console.log('Card is', typeof Card, '| Button module exports:', Object.keys(Buttons))2Match what you see, then jump to its fix
- 1
The log shows typeof undefined for the import, and the module's export list contains the component under a name, or only default.A default import of a named export, or a named import of a default exportFix - 2
The same import works in one entry file and fails in another, or in tests but not in the app, and two files (or a barrel index) import each other directly or through a third.A circular import: the module you import has not finished running yetFix - 3
The component is loaded with lazy(() => import('./Chart')), and ./Chart exports it by name.React.lazy loads a module that has no default exportFix - 4
A compound component such as Menu.Item or Tabs.Panel works inside a file marked 'use client', but renders this error when a Server Component uses it. The App Router is in use.In Next.js, a Server Component uses a static member of a Client ComponentFix
- 1
What does the error look like?
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.Check the render method of `Dashboard`.
Cause 1 of 4
A default import of a named export, or a named import of a default export
1Check
The React docs state the rule: a file has at most one default export, the default import can take any local name, and a named import must use the same name with curly braces. Mixing them gives you undefined instead of the component. The namespace import in the first step lists exactly what the file exports.
grep -nE "export (default|const|function|\{)" src/components/Button.jsx
grep -rn "from './Button'" src2Fix
Make the import match the export, or change the export. Pick one style per project so the mistake cannot happen silently, and avoid unnamed defaults, which also make debugging harder.
// Button.jsx
export function Button() { /* ... */ } // named export
// correct
import { Button } from './Button'
// wrong: gives undefined, because there is no default export
import Button from './Button'
// default export version
export default function Button() { /* ... */ }
import Button from './Button'3Verify
The log now prints function for the import and the page renders.
console.log(typeof Button) // 'function'Confirmed by react.dev
Cause 2 of 4
A circular import: the module you import has not finished running yet
1Check
A cycle arises when module a imports b and b depends on a. The MDN guide explains that when one module runs inside a cycle, the other's const, let and class bindings are not initialised yet, and reading them at that moment fails; only function declarations survive. A barrel file (index.js that re-exports everything) is a common way to close a cycle. Find cycles with a tool.
npx madge --circular --extensions js,jsx,ts,tsx src2Fix
Break the cycle, using the techniques MDN lists: move the shared code into a third module, merge the two modules, or move code from one module to the other. Components should import siblings from their own file, not from the barrel that re-exports them.
// before: Card.jsx and index.js import each other
import { Button } from './index'
// after: import the file that defines it
import { Button } from './Button'3Verify
The cycle report is empty and the import resolves in every entry point.
npx madge --circular --extensions js,jsx,ts,tsx src # prints no circular dependenciesConfirmed by developer.mozilla.org
Cause 3 of 4
React.lazy loads a module that has no default export
1Check
The React docs require the loader to resolve to an object whose default property is a valid component. A file with only named exports resolves to an object without that property.
grep -rn "lazy(" src
grep -n "export" src/components/Chart.jsx2Fix
Export the component as the default, or map the named export to default inside the loader.
const Chart = lazy(() =>
import('./Chart').then((m) => ({ default: m.Chart }))
)3Verify
The component renders after its chunk loads, with no error boundary firing.
// open the page, watch the network tab load the chunk, and check the console is cleanConfirmed by react.dev
Cause 4 of 4
In Next.js, a Server Component uses a static member of a Client Component
1Check
Next.js documents this case: a Server Component that imports a Client Component receives a client reference, not the function, so a property attached to the component is undefined and React throws this error. Check whether the failing tag is a dotted member and where the 'use client' line is.
grep -rnE "<[A-Z][A-Za-z]*\.[A-Z]" app components
grep -rln "^.use client" app components2Fix
Use the compound component from another Client Component, or, to use its pieces from a Server Component, export each piece by name from the client file and import them by name.
// components/menu.tsx
'use client'
export function Menu({ children }: { children: React.ReactNode }) { /* ... */ }
export function MenuItem({ children }: { children: React.ReactNode }) { /* ... */ }
// app/page.tsx (Server Component)
import { Menu, MenuItem } from '@/components/menu'
export default function Page() {
return <Menu><MenuItem>Settings</MenuItem></Menu>
}3Verify
The page renders in the browser and the terminal shows no error for that route.
npm run buildConfirmed by nextjs.org
How do I stop it coming back?
- Use one export style for components (named everywhere, or default everywhere) and enforce it in review.
- Keep barrel files out of component folders that import each other, or lint for cycles in CI.
- Give lazy-loaded components a default export, or write the .then mapping next to the lazy call.
- In the App Router, export compound-component parts by name instead of attaching them as static properties.
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
React says a Hook was called where React is not rendering a component
Uncaught TypeError: Cannot read properties of null (reading 'useState')
A Hook only works while React is rendering a function component or a custom Hook.
4 causes, each with a fixWeb apps
ESLint says an element in a list is missing its key prop
react/jsx-key
react/jsx-key fires when an element returned from map, Array.from or an array literal has no key.
3 causes, each with a fixWeb apps
There is no tailwind.config.js after installing Tailwind 4 and HeroUI in Next.js
HeroUI components render unstyled
Nothing is broken: Tailwind CSS 4 is configured in CSS and no longer creates tailwind.config.js.
3 causes, each with a fixWeb apps
react-i18next shows the wrong plural form for a count, or prints the key instead of the text
t('item') prints the key item instead of a translated sentence
i18next picks a plural from the count option and looks for keys ending in _one, _other and so on.
4 causes, each with a fixWeb apps
useSession throws because there is no SessionProvider above it
[next-auth]: `useSession` must be wrapped in a <SessionProvider />
useSession reads the session from React Context, and SessionProvider is what creates that context.
3 causes, each with a fixWeb apps
next/link throws React.Children.only on its children
Error: React.Children.only expected to receive a single React element child.
React.Children.only accepts exactly one React element and throws for anything else, including an array with one item.
3 causes, each with a fix