TypeScript says my component cannot be used as a JSX component
'Component' cannot be used as a JSX component.Short answer
Before TypeScript 5.1 every JSX tag had to return exactly JSX.Element, so components returning anything wider were rejected. Update TypeScript and the React type packages to current versions. If the message is about children, React 18 types no longer add children for you: declare it in the props.
Fix it fast
1Find out which cause you have
Print the versions of TypeScript and the React types your editor really uses. Old versions of either are behind most of these errors.
npx tsc --version npm ls @types/react2Match what you see, then jump to its fix
- 1
The message says the return type is not a valid JSX element, for a component that renders fine at runtimeTypeScript or the React types are older than the JSX tag-type rulesFix - 2
The error appears on a component that wraps other elements, and complains about the children prop or about {}The props type is missing children (React 18 types)Fix
- 1
What does the error look like?
'Component' cannot be used as a JSX component.Its return type 'Promise<Element>' is not a valid JSX element.Type '{}' is not assignable to type 'ReactNode'
Cause 1 of 2
TypeScript or the React types are older than the JSX tag-type rules
1Check
TypeScript 5.1 stopped requiring every JSX tag to return JSX.Element and added JSX.ElementType, which the React types can fill in. On older TypeScript, a component returning a Promise or a wider type is rejected.
npx tsc --version2Fix
Upgrade TypeScript and the React type packages.
npm install --save-dev typescript@latest @types/react@latest3Verify
The type check passes.
npx tsc --noEmitConfirmed by typescriptlang.org
Cause 2 of 2
The props type is missing children (React 18 types)
1Check
With the React 18 types, a component receives children only when its props type lists the prop. A component typed with only its own props rejects the elements placed inside it.
grep -rn "children" src --include=*.tsx | head2Fix
List children explicitly in the props, as the React 18 upgrade guide shows.
interface MyButtonProps {
color: string;
children?: React.ReactNode;
}3Verify
The type check passes, and the component still renders its children.
npx tsc --noEmitConfirmed by react.dev
How do I stop it coming back?
- Upgrade TypeScript and @types/react together, and commit the lock file.
- Run tsc --noEmit in CI so a type error cannot reach a release build.
- When you upgrade React, read the TypeScript section of its upgrade guide in the same sitting.
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
TypeScript marks className as an error on React Native components
Property 'className' does not exist on type
React Native components have no className prop in their own types.
3 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
TypeScript refuses JSX because the jsx option is not set
TS17004: Cannot use JSX unless the '--jsx' flag is provided.
TypeScript compiles JSX only when you name the file with a .tsx extension and enable the jsx compiler option.
2 causes, each with a fixWeb apps
TypeScript rejects a component that returns an array or other non-Element
Its return type 'Element[]' is not a valid JSX element.
TypeScript before 5.1 required every component to return JSX.Element or null, so arrays, strings and Promises were rejected even though React renders them.
2 causes, each with a fixWeb apps
ESLint says it cannot resolve a path to a module that does exist
Unable to resolve path to module 'react'. import/no-unresolved
import/no-unresolved fails when eslint-plugin-import cannot find the file or package on disk with its resolver.
4 causes, each with a fixWeb apps
ESLint reports no-unused-vars for React components and imports that are used
no-unused-vars reported for a component that is rendered as a JSX tag
ESLint's core no-unused-vars does not see variables used only as JSX tags, so a component imported and rendered as <Hello /> looks unused.
3 causes, each with a fix