Babel React Preset
babel-preset-react (version 6.24.1 provided, associated with Babel 6) is an official Babel preset that bundles plugins essential for transpiling React-specific syntax, such as JSX. It includes transforms like `syntax-jsx`, `transform-react-jsx`, and `transform-react-display-name`. This particular package, `babel-preset-react`, is now considered deprecated as it belongs to the end-of-life Babel 6 ecosystem. Its functionality has been superseded by the actively maintained `@babel/preset-react` package (current stable version 7.x, with 8.x in release candidate as of March 2026). The release cadence for `babel-preset-react` (v6) is effectively ceased, with all development continuing on its scoped successor. For current React development, migrating to `@babel/preset-react` with Babel 7 or newer is the standard practice, offering compatibility with modern JavaScript and React features.
Common errors
-
Error: Cannot find module 'babel-preset-react' from '...'
cause You are likely using Babel 7+ but your configuration or `package.json` still references the deprecated, unscoped `babel-preset-react` package from Babel 6.fixInstall the modern scoped preset: `npm install --save-dev @babel/preset-react`. Then, update your Babel configuration (e.g., `.babelrc` or `babel.config.js`) to use `"@babel/react"` instead of `"react"` in your `presets` array. -
TypeError: Preset react is not a function
cause This typically indicates an incorrect Babel configuration, such as passing options to a preset without wrapping it in an array (`"react", { ... }` instead of `["react", { ... }]`). It can also occur if a Babel 6 preset is loaded by a Babel 7+ core in a non-standard way.fixEnsure your preset configuration adheres to the correct array syntax for options (e.g., `['@babel/react', { runtime: 'automatic' }]`). Verify that your Babel core and preset versions are compatible and that you are using the scoped `@babel/preset-react` for Babel 7+. -
SyntaxError: Unexpected token '<'
cause Babel is failing to process JSX syntax, usually because `@babel/preset-react` is either missing from your Babel configuration or is not being applied to your React files.fixDouble-check that `@babel/preset-react` is included in your Babel configuration's `presets` array and that your build tool (e.g., Webpack, Rollup) is correctly configured to apply Babel to your `.jsx` or `.tsx` files. Ensure you have installed `@babel/preset-react`.
Warnings
- breaking The `babel-preset-react` package (unscoped) is for Babel 6 and is deprecated. Babel 7 introduced scoped packages, meaning all core Babel components, including presets, moved to the `@babel/` namespace. Using `babel-preset-react` with Babel 7+ core will result in module not found errors or incompatible behavior.
- gotcha The order of presets and plugins in your Babel configuration is crucial. For `@babel/preset-react`, ensure it's positioned correctly relative to other syntax transforms (e.g., `@babel/preset-typescript` or `@babel/preset-flow`) and optimization plugins. Incorrect order can lead to unexpected transpilation errors or inefficient output.
- deprecated The `babel-preset-react` package (version 6.x) is end-of-life and no longer receives updates or bug fixes. Continuing to use this version for new projects or in actively developed existing projects is strongly discouraged due to potential security vulnerabilities and lack of support for modern JavaScript and React features.
- breaking As Babel 8 is in release candidate stages, significant breaking changes are anticipated across the entire Babel ecosystem, including `@babel/preset-react`. While specific details are still being finalized, users should expect to update `@babel/core` and all related presets/plugins when migrating to the stable Babel 8 release.
Install
-
npm install babel-preset-react -
yarn add babel-preset-react -
pnpm add babel-preset-react
Imports
- Preset in .babelrc (Babel 6)
{ "presets": ["@babel/react"] }{ "presets": ["react"] } - Preset in .babelrc / babel.config.js (Babel 7+)
{ "presets": ["react"] }{ "presets": ["@babel/react"] } - Programmatic Import (Babel 7+)
import presetReact from 'babel-preset-react';
import presetReact from '@babel/preset-react';
Quickstart
import { transformSync } from '@babel/core';
import presetReact from '@babel/preset-react';
// Install: npm install --save-dev @babel/core @babel/preset-react
const reactCode = `
import React from 'react';
interface MyComponentProps {
name: string;
}
function MyComponent({ name }: MyComponentProps) {
return (
<div>
<h1>Hello, {name}!</h1>
<p>This is a React component using modern JSX syntax.</p>
</div>
);
}
export default MyComponent;
`;
try {
const result = transformSync(reactCode, {
presets: [
// For Babel 7+, use the scoped preset name.
// Ensure '@babel/preset-react' is installed.
['@babel/react', { runtime: 'automatic' }]
],
filename: 'test.tsx' // Helps Babel resolve plugins based on file extension
});
if (result && result.code) {
console.log('Transpiled React code (Babel 7+):
', result.code);
} else {
console.error('Failed to transpile code.');
}
} catch (error) {
console.error('Babel transformation error:', error);
}