Skip to content

@react-native/metro-babel-transformer keeps its first Babel config, so without a Babel config one Metro server bundles Android with iOS's Platform.OS #60030

Open

Description

@YevheniiKotyrlo

Description

In a project with no .babelrc, .babelrc.js or babel.config.js, one Metro server bundles the second platform it is asked for with the first platform's Platform.OS: after an iOS bundle, Platform.OS in the Android bundle is "ios", and after an Android bundle, the iOS bundle's is "android". A server that bundles one platform gives it its own, and so does a server with the template's babel.config.js.

getBabelRC builds its config on the first transform call and returns it to every later call in the process. With no project Babel config, that config is @react-native/babel-preset with the first call's options, and the preset takes unstable_transformProfile, dev, platform, inlinePlatform and disableImportExportTransform from those options before Babel's caller or env, so the caller each call passes does not reach it.

Expected: each bundle's Platform.OS is its own platform's, whichever platform the server bundled first, with or without a project Babel config.

Steps to reproduce

  1. Clone https://github.com/YevheniiKotyrlo/react-native-metro-first-platform. NoBabelConfigApp/ has no Babel config file, the template's metro.config.js, an index.js that registers App.js, and this App.js:
    import {Platform, Text} from 'react-native';
    
    const bundledFor = Platform.OS;
    
    export default function App() {
      return <Text>Platform.OS: {bundledFor}</Text>;
    }
  2. Run bash NoBabelConfigApp/repro.sh. It installs react-native and @react-native/* at 0.90.0-nightly-20261116-a1b2862a5. Each node repro.js <platforms> it runs starts one Metro server from metro.config.js (Metro as @react-native/community-cli-plugin loads it, default maxWorkers, transform cache off), requests /index.bundle?platform=<platform>&dev=true&minify=false for each platform in order, and prints bundledFor from each bundle. It runs ios,android and android,ios, then ios and android alone, then both orders again with the template's babel.config.js written into the folder.
  3. Expected: bundledFor = "ios" in every iOS bundle and bundledFor = "android" in every Android bundle. Actual: the second bundle a server builds has the first platform's:
    GET /index.bundle?platform=ios&dev=true&minify=false -> 200, 3973578 bytes; App.js: bundledFor = "ios"
    GET /index.bundle?platform=android&dev=true&minify=false -> 200, 3986775 bytes; App.js: bundledFor = "ios"
    FAIL: requested in the order ios, android from one Metro server, the android bundle has Platform.OS === "ios"
    
    GET /index.bundle?platform=android&dev=true&minify=false -> 200, 3986239 bytes; App.js: bundledFor = "android"
    GET /index.bundle?platform=ios&dev=true&minify=false -> 200, 3973184 bytes; App.js: bundledFor = "android"
    FAIL: requested in the order android, ios from one Metro server, the ios bundle has Platform.OS === "android"
    
    Each platform alone, and both orders with babel.config.js, pass. bash NoBabelConfigApp/repro.sh 0.88.1 (Metro 0.87.3) fails the same way.

The nightly is built from main at a1b2862; neither packages/react-native-babel-transformer nor packages/react-native-babel-preset has a later commit on main (5534fd9).

React Native Version

0.88.1

Affected Platforms

Runtime - Android, Runtime - iOS, Build - Windows

Output of npx @react-native-community/cli info

node v26.12.1, Windows_NT 10.0.26300 x64, react-native 0.90.0-nightly-20261116-a1b2862a5, metro 0.88.0, @react-native/metro-babel-transformer 0.90.0-nightly-20261116-a1b2862a5, @react-native/babel-preset 0.90.0-nightly-20261116-a1b2862a5

Stacktrace or Logs

$ npm install

$ node repro.js ios,android
node v26.12.1, Windows_NT 10.0.26300 x64, react-native 0.90.0-nightly-20261116-a1b2862a5, metro 0.88.0, @react-native/metro-babel-transformer 0.90.0-nightly-20261116-a1b2862a5, @react-native/babel-preset 0.90.0-nightly-20261116-a1b2862a5
Babel config files in the project: none
Metro config: metro.config.js, maxWorkers 17, transformer node_modules\@react-native\metro-babel-transformer\src\index.js, transform cache off
GET /index.bundle?platform=ios&dev=true&minify=false -> 200, 3973578 bytes; App.js: bundledFor = "ios"
GET /index.bundle?platform=android&dev=true&minify=false -> 200, 3986775 bytes; App.js: bundledFor = "ios"
FAIL: requested in the order ios, android from one Metro server, the android bundle has Platform.OS === "ios"
(exit 1)

$ node repro.js android,ios
node v26.12.1, Windows_NT 10.0.26300 x64, react-native 0.90.0-nightly-20261116-a1b2862a5, metro 0.88.0, @react-native/metro-babel-transformer 0.90.0-nightly-20261116-a1b2862a5, @react-native/babel-preset 0.90.0-nightly-20261116-a1b2862a5
Babel config files in the project: none
Metro config: metro.config.js, maxWorkers 17, transformer node_modules\@react-native\metro-babel-transformer\src\index.js, transform cache off
GET /index.bundle?platform=android&dev=true&minify=false -> 200, 3986239 bytes; App.js: bundledFor = "android"
GET /index.bundle?platform=ios&dev=true&minify=false -> 200, 3973184 bytes; App.js: bundledFor = "android"
FAIL: requested in the order android, ios from one Metro server, the ios bundle has Platform.OS === "android"
(exit 1)

$ node repro.js ios
node v26.12.1, Windows_NT 10.0.26300 x64, react-native 0.90.0-nightly-20261116-a1b2862a5, metro 0.88.0, @react-native/metro-babel-transformer 0.90.0-nightly-20261116-a1b2862a5, @react-native/babel-preset 0.90.0-nightly-20261116-a1b2862a5
Babel config files in the project: none
Metro config: metro.config.js, maxWorkers 17, transformer node_modules\@react-native\metro-babel-transformer\src\index.js, transform cache off
GET /index.bundle?platform=ios&dev=true&minify=false -> 200, 3973578 bytes; App.js: bundledFor = "ios"
PASS: requested in the order ios, each bundle has its own Platform.OS
(exit 0)

$ node repro.js android
node v26.12.1, Windows_NT 10.0.26300 x64, react-native 0.90.0-nightly-20261116-a1b2862a5, metro 0.88.0, @react-native/metro-babel-transformer 0.90.0-nightly-20261116-a1b2862a5, @react-native/babel-preset 0.90.0-nightly-20261116-a1b2862a5
Babel config files in the project: none
Metro config: metro.config.js, maxWorkers 17, transformer node_modules\@react-native\metro-babel-transformer\src\index.js, transform cache off
GET /index.bundle?platform=android&dev=true&minify=false -> 200, 3986239 bytes; App.js: bundledFor = "android"
PASS: requested in the order android, each bundle has its own Platform.OS
(exit 0)

babel.config.js: module.exports = {presets: ['module:@react-native/babel-preset']};

$ node repro.js ios,android
node v26.12.1, Windows_NT 10.0.26300 x64, react-native 0.90.0-nightly-20261116-a1b2862a5, metro 0.88.0, @react-native/metro-babel-transformer 0.90.0-nightly-20261116-a1b2862a5, @react-native/babel-preset 0.90.0-nightly-20261116-a1b2862a5
Babel config files in the project: babel.config.js
Metro config: metro.config.js, maxWorkers 17, transformer node_modules\@react-native\metro-babel-transformer\src\index.js, transform cache off
GET /index.bundle?platform=ios&dev=true&minify=false -> 200, 3973578 bytes; App.js: bundledFor = "ios"
GET /index.bundle?platform=android&dev=true&minify=false -> 200, 3986312 bytes; App.js: bundledFor = "android"
PASS: requested in the order ios, android, each bundle has its own Platform.OS
(exit 0)

$ node repro.js android,ios
node v26.12.1, Windows_NT 10.0.26300 x64, react-native 0.90.0-nightly-20261116-a1b2862a5, metro 0.88.0, @react-native/metro-babel-transformer 0.90.0-nightly-20261116-a1b2862a5, @react-native/babel-preset 0.90.0-nightly-20261116-a1b2862a5
Babel config files in the project: babel.config.js
Metro config: metro.config.js, maxWorkers 17, transformer node_modules\@react-native\metro-babel-transformer\src\index.js, transform cache off
GET /index.bundle?platform=android&dev=true&minify=false -> 200, 3986239 bytes; App.js: bundledFor = "android"
GET /index.bundle?platform=ios&dev=true&minify=false -> 200, 3973651 bytes; App.js: bundledFor = "ios"
PASS: requested in the order android, ios, each bundle has its own Platform.OS
(exit 0)

SUMMARY: FAIL - without a Babel config, the bundle a Metro server builds second carries the Platform.OS of the platform it built first; each platform alone, and both with babel.config.js, carry their own

MANDATORY Reproducer

https://github.com/YevheniiKotyrlo/react-native-metro-first-platform

Screenshots and Videos

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions