Babel Preset for Create React App

10.1.0 · active · verified Sun Apr 19

babel-preset-react-app is the official Babel preset utilized by Create React App (CRA) projects to transpile modern JavaScript and React syntax into backward-compatible code. It bundles configurations for React JSX, class properties, object rest/spread, dynamic imports, and various ECMAScript features, along with Flow or TypeScript support. The current stable version is 10.1.0 (as of the prompt's context, reflecting the package version). Its release cadence is tightly coupled with Create React App's development, typically receiving updates when CRA itself has major dependency upgrades (e.g., Webpack, Jest, ESLint) or introduces new features. Key differentiators include its opinionated, zero-config approach for CRA users, providing a robust and battle-tested setup that integrates seamlessly with the CRA ecosystem without manual Babel configuration, contrasting with more custom or granular Babel setups.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates the basic `.babelrc` configuration for `babel-preset-react-app`, including options for TypeScript and absolute runtime paths. This file should be in your project root.

{
  "presets": [
    [
      "react-app",
      {
        "flow": false,
        "typescript": true, // Set to true if using TypeScript, false otherwise.
        "absoluteRuntime": true // Use absolute paths for Babel helper imports
      }
    ]
  ]
}

// Example React component in src/App.tsx (if typescript: true)
// import React from 'react';

// const App: React.FC = () => {
//   const [count, setCount] = React.useState(0);
//   const increment = () => setCount(prev => prev + 1);

//   return (
//     <div>
//       <h1>Hello from React App!</h1>
//       <p>Count: {count}</p>
//       <button onClick={increment}>Increment</button>
//     </div>
//   );
// };

// export default App;

view raw JSON →