The target option specifies which React version the compiler should generate code for.
Reference
Section titled “Reference”target
Section titled “target”Configures the React version compatibility for the compiled output.
'17' | '18' | '19'Default value
Section titled “Default value”'19'
Valid values
Section titled “Valid values”'19': Target React 19 (default). No additional runtime required.'18': Target React 18. Requiresreact-compiler-runtimepackage.'17': Target React 17. Requiresreact-compiler-runtimepackage.
Caveats
Section titled “Caveats”- Always use string values, not numbers (e.g.,
'17'not17) - Don’t include patch versions (e.g., use
'18'not'18.2.0') - React 19 includes built-in compiler runtime APIs
- React 17 and 18 require installing
react-compiler-runtime@latest
Targeting React 19 (default)
Section titled “Targeting React 19 (default)”For React 19, no special configuration is needed:
The compiler will use React 19’s built-in runtime APIs:
// Compiled output uses React 19's native APIsimport { c as _c } from 'react/compiler-runtime';Targeting React 17 or 18
Section titled “Targeting React 17 or 18”For React 17 and React 18 projects, you need two steps:
- Install the runtime package:
npm install react-compiler-runtime@latest- Configure the target:
// For React 18{ target: '18'}
// For React 17{ target: '17'}The compiler will use the polyfill runtime for both versions:
// Compiled output uses the polyfillimport { c as _c } from 'react-compiler-runtime';Troubleshooting
Section titled “Troubleshooting”Runtime errors about missing compiler runtime
Section titled “Runtime errors about missing compiler runtime”If you see errors like “Cannot find module ‘react/compiler-runtime’”:
-
Check your React version:
Terminal window npm why react -
If using React 17 or 18, install the runtime:
Terminal window npm install react-compiler-runtime@latest -
Ensure your target matches your React version:
Runtime package not working
Section titled “Runtime package not working”Ensure the runtime package is:
- Installed in your project (not globally)
- Listed in your
package.jsondependencies - The correct version (
@latesttag) - Not in
devDependencies(it’s needed at runtime)
Checking compiled output
Section titled “Checking compiled output”To verify the correct runtime is being used, note the different import (react/compiler-runtime for builtin, react-compiler-runtime standalone package for 17/18):
// For React 19 (built-in runtime)import { c } from 'react/compiler-runtime'// ^
// For React 17/18 (polyfill runtime)import { c } from 'react-compiler-runtime'// ^