Babel React Preset

6.24.1 · deprecated · verified Tue Apr 21

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the modern `@babel/preset-react` package with `@babel/core` to transpile a TypeScript React component containing JSX. It highlights the standard programmatic usage for Babel 7+ environments.

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);
}

view raw JSON →