@react-native/babel-preset removes every Flow `enum` declaration before babel-plugin-transform-flow-enums sees it, so code that reads the enum throws ReferenceError
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- babel, javascript, react-native
- Ambito
- build-system, mobile
Direzione di ricerca
Read packages/react-native-babel-preset/src/configs/main.js at the plugin ordering described in the issue, then inspect the reproducer and its Babel configuration. Run ./reproduce.sh to confirm the missing enum declarations and the resulting ReferenceError. Done means Flow enums are transformed before stripping while other Flow syntax remains stripped, and the reproducer exits successfully; linked pull request #60034 indicates work is already underway.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
With @react-native/babel-preset alone in an app's babel.config.js, as the template has it, every Flow enum declaration is removed from the output, while the code that reads the enum stays. Loading such a module throws ReferenceError: <Enum> is not defined. This includes React Native's own VirtualView.js, whose VirtualViewMode and VirtualViewRenderState (L26-L37) are read at L103 and later, and whose VirtualViewMode is the public export of index.js L426-L428.
The preset's first override holds @babel/plugin-transform-flow-strip-types alone, and babel-plugin-transform-flow-enums is in the second (main.js L257-L273). strip-types' Flow visitor calls path.remove(), and @babel/types gives EnumDeclaration the alias Flow, so the declaration is gone before the enum plugin visits it. The repository's own .babelrc adds babel-plugin-transform-flow-enums as a top-level plugin, which runs before the preset's plugins; an app's babel.config.js from the template does not.
Expected: an enum declaration becomes require("flow-enums-runtime")(…) (or .Mirrored([…])), as it does with babel-plugin-transform-flow-enums ahead of the preset, and the rest of the Flow syntax is still stripped.
Steps to reproduce
- Clone the reproducer below. Its
ReproducerApp/babel.config.jsis the template's,presets: ['module:@react-native/babel-preset'].ReproducerApp/enum/Status.jsdeclaresexport enum Status {Active, Off}and exportsinitial = Status.Active;enum/index.jsimports both and logsStatus.getName(initial);enum/virtual-view.jsimportsVirtualViewModefromreact-native. - Run
./reproduce.sh. It runsyarn installinReproducerApp, thennode reproduce.js, which bundlesenum/index.jswith Metro and the app'smetro.config.js(Android,dev: false, not minified), prints the bundledStatus.jsmodule, runs the bundle with Node, then bundlesenum/virtual-view.jsthe same way and prints the lines of the bundledVirtualView.jsthat name its two enums. It exits 1 while the enums are dropped and 0 once they are declared. - Expected: the bundle prints
Status.getName(initial): Active, and the bundledVirtualView.jsdeclaresVirtualViewModeandVirtualViewRenderState. Seen: the bundledStatus.jsreadsStatus.Activewith noStatusdeclared, the bundle throwsReferenceError: Status is not defined, and the bundledVirtualView.jsreads both enums with neither declared.
Adding plugins: ['babel-plugin-transform-flow-enums'] to the reproducer's babel.config.js makes it exit 0.
React Native Version
0.90.0-nightly-20261116-a1b2862a5
Affected Platforms
Build - Windows
Output of npx @react-native-community/cli info
System:
OS: Windows 11 10.0.26300
CPU: "(32) x64 AMD Ryzen 9 9950X3D 16-Core Processor "
Memory: 124.21 GB / 255.67 GB
Binaries:
Node:
version: 26.12.1
path: C:\Program Files\nodejs\node.EXE
Yarn:
version: 1.22.22
path: C:\Users\<user>\AppData\Roaming\npm\yarn.CMD
npm:
version: 12.2.1
path: C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
Windows SDK:
AllowDevelopmentWithoutDevLicense: Enabled
Versions:
- 10.0.19041.0
- 10.0.26100.0
IDEs:
Android Studio: AI-262.9437.185.2621.16467767
Visual Studio: Not Found
Languages:
Java:
version: 17.0.20.1
path: C:\Program Files\Microsoft\jdk-17.0.20.101-hotspot\bin\javac.EXE
Ruby: Not Found
npmPackages:
"@react-native-community/cli":
installed: 22.0.0-alpha.0
wanted: 22.0.0-alpha.0
react:
installed: 19.3.0
wanted: 19.3.0
react-native:
installed: 0.90.0-nightly-20261116-a1b2862a5
wanted: 0.90.0-nightly-20261116-a1b2862a5
react-native-windows: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: Not found
newArchEnabled: Not found
Stacktrace or Logs
$ node reproduce.js
node v26.12.1, Windows_NT 10.0.26300 x64, react-native 0.90.0-nightly-20261116-a1b2862a5, @react-native/babel-preset 0.90.0-nightly-20261116-a1b2862a5, metro 0.88.0, @babel/core 7.29.7
babel.config.js: {"presets":["module:@react-native/babel-preset"]}
$ metro build enum/index.js --platform android --dev false --minify false
wrote build\enum.bundle.js
enum/Status.js in the bundle:
__d(function (global, require, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, _dependencyMap) {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.initial = undefined;
var initial = exports.initial = Status.Active;
},1);
$ node build\enum.bundle.js
.\build\enum.bundle.js:759
throw e;
^
ReferenceError: Status is not defined
Node.js v26.12.1
(exit 1)
$ metro build enum/virtual-view.js --platform android --dev false --minify false
wrote build\virtual-view.bundle.js
react-native's VirtualView.js in the bundle, its lines that name VirtualViewMode or VirtualViewRenderState:
var mode = (0, _nullthrows.default)(VirtualViewMode.cast(event.nativeEvent.mode));
renderState: isHidden ? VirtualViewRenderState.None : VirtualViewRenderState.Rendered,
if (mode === VirtualViewMode.Visible) {
if (mode === VirtualViewMode.Prerender) {
if (mode === VirtualViewMode.Hidden) {
renderState: isHidden ? VirtualViewRenderState.None : VirtualViewRenderState.Rendered,
VirtualViewMode and VirtualViewRenderState declared: no
FAIL: @react-native/babel-preset removed the Flow enum declaration `enum Status {Active, Off}`, so the bundle throws ReferenceError: Status is not defined; react-native's own VirtualView.js bundles with VirtualViewMode and VirtualViewRenderState read and never declared
MANDATORY Reproducer
https://github.com/YevheniiKotyrlo/rn-babel-preset-flow-enum-repro
Screenshots and Videos
No response
- Lingua principale
- C++
- Stelle
- 127k
- Fork
- 25.5k
- Merge medio
- 3g 22h
- PR unite (30g)
- 235
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di react/react-native
-
Needs: Author Feedback Needs: Repro
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
react/react-native#60059 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Needs: Triage :mag:
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
react/react-native#60000 ·
I maintainer di solito rispondono entro 2 giorni
-
`yarn test-ios` exits before building RNTester: `objc-test.sh` launches the WebSocket server script #59433 deletedForse già presa @lazerg l’ha presa 4 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
react/react-native#59939 ·
I maintainer di solito rispondono entro 2 giorni
-
iOS Fabric pointer-handler reset leaves the next lone touch non-primaryForse già presa @alleneubank l’ha presa 6 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
react/react-native#59919 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
react/react-native#59722 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di react/react-native
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
petercorke/robotics-toolbox-python#943 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area:build bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
NatronGitHub/openfx-arena#71 ·
I maintainer di solito rispondono entro 1 giorno
-
upstream-watcher: Netflix/vmaf cf677baaa039 is not portedForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaupstream-blocked
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ROCm/FastFlowLM#1057 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
NatronGitHub/openfx-gmic#45 ·
I maintainer di solito rispondono entro 1 giorno