Migrating React Relay from v18 to v19
Relay 19 tightens alias requirements and adds React 19 compatibility.
Key changes
- The
@aliasdirective is required on conditional fragments. Use@dangerously_unaliased_fixmeto suppress or run themark-dangerous-conditional-fragment-spreadscodemod. - Generated JS files use ES module imports by default. Set
"eagerEsModules": falseinrelay.config.jsonto revert. - Pre-bundled modules were removed from npm packages.
- Documentation improvements and React 19 support.
Alias enforcement example
Before upgrading:
fragment ItemPreview on Item @include(if: $show) { name}After upgrade you must add @alias:
fragment ItemPreview on Item @include(if: $show) @alias(localItemPreview) { name}ES module configuration
The compiler now emits ES modules. To retain CommonJS output set:
{ "eagerEsModules": false}Migration steps
- Upgrade to
^19.0.0. - Run the codemod to mark conditional fragment spreads and update code with
@aliasas appropriate. - Verify your build system supports ES module imports or configure the
eagerEsModulesflag. - Regenerate artifacts with the updated compiler.