@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
Mantenedores costumam responder em até 2 dias
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
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 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
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de react/react-native
-
Needs: Author Feedback Needs: Repro
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
react/react-native#60059 · 1 comentário ·
Mantenedores costumam responder em até 2 dias
-
Needs: Triage :mag:
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
react/react-native#60000 ·
Mantenedores costumam responder em até 2 dias
-
`yarn test-ios` exits before building RNTester: `objc-test.sh` launches the WebSocket server script #59433 deletedTalvez já em andamento @lazerg assumiu há 4 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
react/react-native#59939 ·
Mantenedores costumam responder em até 2 dias
-
iOS Fabric pointer-handler reset leaves the next lone touch non-primaryTalvez já em andamento @alleneubank assumiu há 6 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
react/react-native#59919 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
react/react-native#59722 ·
Mantenedores costumam responder em até 2 dias
Todas as issues de react/react-native
Issues semelhantes
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
petercorke/robotics-toolbox-python#943 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
area:build bug
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
NatronGitHub/openfx-arena#71 ·
Mantenedores costumam responder em até 1 dia
-
upstream-watcher: Netflix/vmaf cf677baaa039 is not portedTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Abertaupstream-blocked
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
ROCm/FastFlowLM#1057 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
NatronGitHub/openfx-gmic#45 ·
Mantenedores costumam responder em até 1 dia