Installation
React Compiler consists of two main packages: the Babel plugin for code transformation and the ESLint plugin for validation.Prerequisites
Before installing React Compiler, ensure you have:- Node.js: Version 14.17.0 or higher (16.x, 18.x+ recommended)
- React: Version 19 or experimental builds (
0.0.0-experimental-*) - Babel: Version 7.2.0 or higher (for Babel users)
Installing the Babel Plugin
The Babel plugin performs the actual code transformation.Installing the ESLint Plugin
The ESLint plugin helps catch Rules of React violations before compilation.Installing the Runtime
The compiler generates code that imports fromreact/compiler-runtime. This is included with React 19:
Basic Configuration
After installation, configure the Babel plugin:Verification
To verify the installation is working, create a simple component:MyComponent.jsx
Framework-Specific Setup
Next.js
For Next.js 13.5+:next.config.js
Vite
For Vite with@vitejs/plugin-react:
vite.config.js
Create React App
For CRA, you’ll need to usereact-app-rewired or craco:
Webpack
For custom Webpack setups withbabel-loader:
webpack.config.js
TypeScript Support
React Compiler works with TypeScript out of the box. Ensure you have Babel’s TypeScript preset:babel.config.js
Troubleshooting
”Cannot find module ‘react/compiler-runtime’”
Ensure you’re using React 19 or experimental builds:Compilation Errors
If you see compilation errors:- Check that your code follows the Rules of React
- Install and configure the ESLint plugin
- Review error messages for specific issues
Performance Issues
If compilation is slow:- Use opt-in mode to compile specific files
- Exclude
node_modulesfrom compilation - Enable caching in your build tool
Next Steps
Configuration
Configure compiler options for your project
ESLint Plugin
Set up linting for Rules of React
Babel Plugin
Advanced Babel plugin configuration
How It Works
Understand the compilation process