Repository navigation
Description
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
- Clone https://github.com/YevheniiKotyrlo/react-native-metro-first-platform.
NoBabelConfigApp/has no Babel config file, the template'smetro.config.js, anindex.jsthat registersApp.js, and thisApp.js:import {Platform, Text} from 'react-native'; const bundledFor = Platform.OS; export default function App() { return <Text>Platform.OS: {bundledFor}</Text>; }
- Run
bash NoBabelConfigApp/repro.sh. It installsreact-nativeand@react-native/*at0.90.0-nightly-20261116-a1b2862a5. Eachnode repro.js <platforms>it runs starts one Metro server frommetro.config.js(Metro as@react-native/community-cli-pluginloads it, defaultmaxWorkers, transform cache off), requests/index.bundle?platform=<platform>&dev=true&minify=falsefor each platform in order, and printsbundledForfrom each bundle. It runsios,androidandandroid,ios, theniosandandroidalone, then both orders again with the template'sbabel.config.jswritten into the folder. - Expected:
bundledFor = "ios"in every iOS bundle andbundledFor = "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"Each platform alone, and both orders withGET /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"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
Activity