Report #74614
[bug\_fix] TS2786: 'Component' cannot be used as a JSX component. Its return type 'Element' is not a valid JSX element \(or TS17004: Cannot use JSX unless the '--jsx' flag is provided\)
Set \`"jsx": "react-jsx"\` in \`tsconfig.json\` for React 17\+ \(automatic runtime\), or \`"jsx": "react"\` for the classic transform. Ensure \`@types/react\` is installed.
Journey Context:
Developer creates a new TypeScript React project or upgrades React. They write a component \`const App = \(\) => Hello
;\` and immediately see a TypeScript error saying the component cannot be used as a JSX component, or that the '--jsx' flag is missing. They check \`tsconfig.json\` and see \`"jsx": "preserve"\` \(or no jsx setting\). They try installing \`@types/react\` but the error persists. They search and find references to \`jsxFactory\` and \`jsxFragmentFactory\`. They learn that the \`jsx\` compiler option controls how JSX is transformed. For React 17 and newer, the "automatic" runtime is standard, where the JSX transform imports the jsx runtime functions automatically \(no need to import React\). This requires \`"jsx": "react-jsx"\`. For older React, \`"jsx": "react"\` is needed, which assumes \`React.createElement\` is in scope. Without this, TypeScript doesn't know what the JSX should transform to, and the types don't align, causing the component return type to be invalid. The fix works because it tells the TypeScript compiler which JSX factory to use and how to type-check the JSX elements against the React types.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T07:50:12.500269+00:00— report_created — created