@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

Aberta
#60,030 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 2 dias

@lazerg já está trabalhando nisso.

Desde 16/11/2026.

  • #60036 de @lazerg — aberto

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
babel, javascript, react-native
Domínio
build-system, mobile

Direção de pesquisa

Start with packages/react-native-babel-transformer/src/index.js, especially getBabelRC and the transform call, then inspect packages/react-native-babel-preset/src/configs/main.js for which options the preset reads. Use the linked reproducer to compare bundles requested in both platform orders, with and without a Babel config. Done means each bundle reports its requested platform's Platform.OS; issue #60036 already has an open linked pull request.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

📦Bundler Needs: Triage :mag: Platform: Android Platform: iOS
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 a1b2862a5a; neither packages/react-native-babel-transformer nor packages/react-native-babel-preset has a later commit on main (5534fd964f).

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

Linguagem predominante
C++
Estrelas
127k
Forks
25.5k
Merge médio
3d 22h
PRs com merge (30d)
235

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de react/react-native

Todas as issues de react/react-native

Issues semelhantes

Mais issues de C++

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.