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.
npm install babel-preset-react-appVerified import paths — ran on the pinned version, not inferred.
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.
Review your project's `package.json` and any custom configuration files (`webpack.config.js`, `.eslintrc.js`, `jest.config.js`) for compatibility with the new major versions. Update any plugins or loaders that might conflict.
For existing projects, ensure you are on React 17+. You can safely remove `import React from 'react';` from component files, although leaving it will not cause issues. If you have custom Babel setups, ensure `@babel/plugin-transform-react-jsx` is configured correctly, or rely on this preset.
To use relative paths, set the `absoluteRuntime` option to `false` in your `.babelrc` or Babel configuration file: `["react-app", { "absoluteRuntime": false }]`.If using outside of CRA, ensure you have `@babel/core`, `react`, and any necessary polyfills (`core-js`) installed and configured correctly. For highly customized projects, consider using more granular Babel presets like `@babel/preset-env` and `@babel/preset-react` directly.
Always keep your `react-scripts` package (and by extension, `babel-preset-react-app`) updated to the latest stable version to benefit from bug fixes, performance improvements, and security patches for its bundled dependencies. Run `npm install --save --save-exact react-scripts@latest` or `yarn add --exact react-scripts@latest`.
Ensure `@babel/core`, `babel-loader`, and `babel-preset-react-app` are installed as `devDependencies`. If you are manually managing Babel dependencies, verify all necessary presets and plugins (e.g., `@babel/preset-env`, `@babel/plugin-proposal-class-properties`) are installed and correctly configured in your `package.json` and `.babelrc`.
Ensure your `react` and `react-dom` packages are at least `17.0.0` and that `react-scripts` is updated to at least `4.0.0` (or `babel-preset-react-app` to `4.0.0`) to leverage the new JSX transform. Verify your `.babelrc` file does not override or disable the necessary JSX transform options.
Check your Babel configuration order if you have multiple presets/plugins. Ensure `babel-preset-react-app` is applied correctly. If using `react-scripts`, make sure you haven't ejected and introduced conflicting Babel configurations. Update `react-scripts` to the latest version.
You can either: 1) Add `import React from 'react';` at the top of your TypeScript files if `isolatedModules` is enabled. 2) Set the `jsx` compiler option in `tsconfig.json` to `'react-jsx'` or `'react-jsxdev'` for React 17+ projects, which informs TypeScript about the new JSX transform and removes the need for explicit `React` imports.
No dependency data recorded yet.