How to fix JSX transform failed in React
JSX transform failures occur when your build tool cannot convert JSX syntax into JavaScript, typically due to missing Babel plugins, incorrect configuration, or version mismatches between React and your build tooling.
Quick fix
Fixes JSX transform failed
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}- Verify Babel configuration includes React preset
- Install missing Babel dependencies
- Configure TypeScript jsx compiler option
- Update React to version 17 or higher if using automatic runtime
{"presets": ["@babel/preset-env","@babel/preset-react"]}JSX transform failed
What this error means
JSX transform failures happen when the build process cannot convert JSX syntax into regular JavaScript that browsers can execute. JSX is not valid JavaScript - it's a syntax extension that needs to be transformed (transpiled) by tools like Babel or TypeScript before it can run. When this transformation fails, your build process stops and you cannot run your React application. This error commonly appears in several forms: "Support for the experimental syntax 'jsx' isn't currently enabled", "Cannot find module '@babel/plugin-transform-react-jsx'", or "'jsx' is not exported by node_modules/react/jsx-runtime.js". Each variation points to different configuration issues in your build pipeline. The transformation process involves either the classic transform (converting JSX to React.createElement calls) or the newer automatic runtime introduced in React 17 (which auto-imports special functions from react/jsx-runtime). Failures can occur at any stage - missing dependencies, incorrect Babel configuration, TypeScript compiler settings, or version incompatibilities between React and build tools.
Typical symptoms
- Build process fails with 'Support for the experimental syntax jsx isn't currently enabled'
- Error message 'Cannot find module @babel/plugin-transform-react-jsx' appears after ejecting from Create React App
- TypeScript shows 'Cannot use JSX unless the --jsx flag is provided'
- Jest tests fail to parse JSX files with syntax errors
- Build succeeds but runtime error 'jsx is not exported by react/jsx-runtime.js' occurs
- Webpack or Vite build hangs or crashes when processing .jsx or .tsx files
- Components with JSX render as '[object Object]' instead of proper HTML
Common causes
- Missing @babel/preset-react or @babel/plugin-transform-react-jsx in Babel configuration
- Babel dependencies not installed or corrupted node_modules directory
- TypeScript tsconfig.json missing or has incorrect 'jsx' compiler option setting
- React version older than 17.0 being used with automatic JSX runtime configuration
- Build tool (Webpack, Vite, esbuild) configured to use 'js' loader for files containing JSX
- Conflicting Babel presets or plugins that override JSX transformation settings
- Jest configuration missing babel-jest or preset-react for test transformation
- Working directory contains symbolic links preventing proper module resolution
How to fix "JSX transform failed"
Check your .babelrc, babel.config.js, or package.json for Babel configuration. Ensure you have @babel/preset-react in the presets array:
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}If using the new automatic JSX runtime (React 17+), configure it explicitly:
{
"presets": [
["@babel/preset-react", { "runtime": "automatic" }]
]
}The runtime: "automatic" option enables the new transform that doesn't require importing React in every file.
Install the required Babel packages if they're missing:
npm install --save-dev @babel/preset-react @babel/plugin-transform-react-jsxOr with Yarn:
yarn add --dev @babel/preset-react @babel/plugin-transform-react-jsxIf you recently ejected from Create React App or suspect corrupted dependencies, delete node_modules and reinstall:
rm -rf node_modules package-lock.json
npm installEnsure your Babel version is 7.9.0 or higher for new JSX transform support: npm list @babel/core.
If using TypeScript, verify your tsconfig.json has the correct jsx setting:
For React 17+ with automatic runtime:
{
"compilerOptions": {
"jsx": "react-jsx"
}
}For React 16 and earlier (classic runtime):
{
"compilerOptions": {
"jsx": "react"
}
}The react-jsx option uses the new automatic runtime, while react uses the classic React.createElement transform.
The automatic JSX runtime requires React 17.0.0 or later. Check your current version:
npm list reactIf below 17.0.0 and you've configured automatic runtime, either upgrade React:
npm install react@latest react-dom@latestOr revert your Babel/TypeScript configuration to use classic runtime by removing "runtime": "automatic" from Babel preset options and setting TypeScript's jsx to "react" instead of "react-jsx".
Ensure your build tool recognizes JSX syntax in your files:
Webpack: Verify babel-loader processes .jsx and .js files containing JSX:
module.exports = {
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: 'babel-loader'
}
]
}
};Vite: Add esbuild jsx configuration if using .js files with JSX:
export default {
esbuild: {
loader: 'jsx',
include: /src/.*\.jsx?$/,
}
}Alternatively, rename files with JSX from .js to .jsx extension.
If JSX transform fails in Jest tests, ensure your Jest configuration includes proper transformation:
In jest.config.js or package.json:
module.exports = {
transform: {
'^.+\.(js|jsx|ts|tsx)$': 'babel-jest'
}
};Install babel-jest if missing:
npm install --save-dev babel-jestEnsure your .babelrc or babel.config.js is in the project root where Jest can find it.
If your terminal is in a directory accessed via symbolic links, React's build tools may fail to resolve modules correctly. Get the real path:
pwd -PNavigate to the actual path (not the symlink) and run your build command:
cd $(pwd -P)
npm startThis ensures Create React App and other tools resolve dependencies from the correct absolute path.
Advanced notes
ESLint Configuration: When using automatic JSX runtime, you can disable the react/jsx-uses-react and react/react-in-jsx-scope ESLint rules since importing React is no longer necessary. Add to your .eslintrc:
{
"rules": {
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off"
}
}Pragma Conflicts: Avoid mixing JSX pragmas (/** @jsx */ or /** @jsxFrag */) with automatic runtime - you'll get "pragma and pragmaFrag cannot be set when runtime is automatic". Remove pragma comments when using runtime: "automatic".
Build Tool Differences: Different build tools handle JSX transformation differently. Create React App includes all necessary configuration out of the box, Vite uses esbuild for fast transformation, and custom Webpack setups require explicit babel-loader configuration. If migrating between tools, verify each tool's JSX handling requirements.
Monorepo Considerations: In monorepos with hoisted dependencies, ensure @babel/preset-react is installed at the workspace root or configure Babel to resolve presets from the correct location using the rootMode option.
React Native Web: When using react-native-web, packages may fail with JSX syntax errors if they're not transpiled. Configure your build tool to process specific node_modules packages that contain untranspiled JSX.
Frequently asked questions
- What does "JSX transform failed" mean?
- JSX transform failures happen when the build process cannot convert JSX syntax into regular JavaScript that browsers can execute. JSX is not valid JavaScript - it's a syntax extension that needs to be transformed (transpiled) by tools like Babel or TypeScript before it can run. When this transformation fails, your build process stops and you cannot run your React application.
- How do I fix "JSX transform failed"?
- JSX transform failures occur when your build tool cannot convert JSX syntax into JavaScript, typically due to missing Babel plugins, incorrect configuration, or version mismatches between React and your build tooling.
- What causes "JSX transform failed"?
- Missing @babel/preset-react or @babel/plugin-transform-react-jsx in Babel configuration Babel dependencies not installed or corrupted node_modules directory TypeScript tsconfig.json missing or has incorrect 'jsx' compiler option setting
- Is the "JSX transform failed" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐React Official Documentation
- ๐React Official: Introducing the New JSX Transform(Official Docs)
- ๐Babel Docs: @babel/plugin-transform-react-jsx(Official Docs)
- ๐
- ๐
- ๐