Skip to content

[0.76 RC] Babel preset is incomplete without hermes-parser #46601

Description

@jbroma

Description

Problem

JavaScript files using newer Flow syntax (e.g., as type casts) fail to transpile correctly in React Native's Metro preset when hermesParser is disabled. This is because babel-parser no longer fully supports Flow, and Hermes parser is now required for handling the latest Flow features.

Background

  1. babel-parser no longer fully supports newer Flow features due to the Flow plugin being unmaintained:
    [Discussion] Remove flow support from @babel/parser babel/babel#16264.
  2. React Native has enabled hermesParser by default in 0.76.0:
    RN: Enable Hermes Parser in RNTester / CI #46318

Proposed Solution

To make the Metro preset self-sufficient, we should consider including babel-plugin-syntax-hermes-parser in the preset. This would ensure that even when used without metro, babel can still transpile newer flow syntax properly.

Steps to reproduce

  1. yarn install
  2. yarn react-native start
  3. Trigger compilation by going to http://localhost:8081/index.bundle?platform=ios in the browser or by running the app

React Native Version

0.76.0-rc.1

Affected Platforms

Build - MacOS, Build - Windows, Build - Linux

Output of npx react-native info

System:
OS: macOS 14.6.1
CPU: (10) arm64 Apple M1 Pro
Memory: 148.48 MB / 32.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 20.13.1
path: ~/Library/Caches/fnm_multishells/27637_1727087645332/bin/node
Yarn:
version: 4.5.0
path: ~/Library/Caches/fnm_multishells/27637_1727087645332/bin/yarn
npm:
version: 10.5.2
path: ~/Library/Caches/fnm_multishells/27637_1727087645332/bin/npm
Watchman:
version: 2024.09.09.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.15.2
path: /Users/jbroma/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.0
- iOS 18.0
- macOS 15.0
- tvOS 18.0
- visionOS 2.0
- watchOS 11.0
Android SDK: Not Found
IDEs:
Android Studio: 2024.1 AI-241.18034.62.2412.12266719
Xcode:
version: 16.0/16A242d
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.12
path: /Users/jbroma/.jenv/shims/javac
Ruby:
version: 2.7.6
path: /Users/jbroma/.rbenv/shims/ruby
npmPackages:
"@react-native-community/cli":
installed: 15.0.0-alpha.2
wanted: 15.0.0-alpha.2
react:
installed: 18.3.1
wanted: 18.3.1
react-native:
installed: 0.76.0-rc.1
wanted: 0.76.0-rc.1
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: Not found
newArchEnabled: false

Stacktrace or Logs

error: SyntaxError: /Users/jbroma/Developer/RN76BabelPresetReproducer/node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js: Unexpected token, expected "]" (39:5)
37 |
38 | type Registry<TEventToArgsMap: {...}> = {
> 39 | [K in keyof TEventToArgsMap]: Set<Registration<TEventToArgsMap[K]>>,
| ^
40 | };
41 |
42 | /**

Reproducer

https://github.com/jbroma/RN76BabelPresetReproducer

Screenshots and Videos

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions