"jsx"
Specifies what the compiler does with JSX syntax in .tsx files.
Example
#{
"compilerOptions": {
"jsx": "react-jsx",
"module": "ESNext",
"moduleResolution": "Bundler"
},
"include": ["src"]
}Definition and usage
#The jsx option tells the compiler how to process JSX markup in .tsx files. Without it, every such tag fails with the error “Cannot use JSX unless the '--jsx' flag is provided”.
With the value react-jsx, JSX is turned into function calls from the react/jsx-runtime module, whose import the compiler adds by itself. This is the recommended setting since React 17: you don’t need to import React in files with JSX. preserve leaves the JSX unchanged for a tool that will process it later, and the older react turns it into React.createElement().
The jsxImportSource option lets you use the same syntax with another library, such as Preact. To type-check JSX, the compiler needs the library’s types, which for React means the @types/react package.
Syntax
#"jsx": "react-jsx"Available values
#react-jsx
_jsx("span", …)
Calls fromreact/jsx-runtime, with the import added automatically. Recommended for React 17 and newer.react-jsxdev
_jsxDEV("span", …)
Likereact-jsx, but with debugging information: the file, line, and column of the tag.preserve
<span>…</span>
JSX is left unchanged, and the output file has the.jsxextension. For projects where a bundler or framework processes the JSX.react
React.createElement("span", …)
The older way.Reactmust be available in every file with JSX.react-native
<span>…</span>
JSX is left unchanged, but the output file has the.jsextension.
More examples
#// src/Badge.tsx
export function Badge({ label }: { label: string }) {
return <span className="badge">{label}</span>
}
// Compilation result with "jsx": "react-jsx":
// import { jsx as _jsx } from "react/jsx-runtime";
// export function Badge({ label }) {
// return _jsx("span", { className: "badge", children: label });
// }{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
}
}Good practices
#- In a Next.js or Vite project, keep the value from the template. The tool sets
jsxthe way its compiler needs it. - The error “This JSX tag requires the module path 'react/jsx-runtime' to exist” means the React types are missing. Install the
@types/reactpackage. - Files with JSX must have the
.tsxextension. In a.tsfile, the tag is read as a type assertion or a comparison, and you get misleading syntax errors.
Related entries
#- "lib"Selects the built-in environment types: the JavaScript version, browser APIs, and individual new language features.
- "module"The module format of the generated code and how imports are understood.
- "target"The JavaScript version the compiler turns your code into.
- "include" and "exclude"Which files the compiler takes into account, and which it skips.
Spotted a mistake or missing an example? Write to us.