Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jbroma opened this issue Sep 23, 2024 · 2 comments
Open

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

jbroma opened this issue Sep 23, 2024 · 2 comments
Labels
Resolution: PR Submitted A pull request with a fix has been provided.

Comments

@jbroma
Copy link
Contributor

jbroma commented Sep 23, 2024

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

@cipolleschi
Copy link
Contributor

We just landed a couple of picks to fix that. We are going to release RC.2 between today and tomorrow morning.
Is it okay to wait for that?

@cortinico cortinico added Resolution: PR Submitted A pull request with a fix has been provided. and removed Needs: Triage 🔍 labels Sep 23, 2024
@jbroma
Copy link
Contributor Author

jbroma commented Sep 23, 2024

We just landed a couple of picks to fix that. We are going to release RC.2 between today and tomorrow morning. Is it okay to wait for that?

absolutely, this just needs to be addressed before stable release of 0.76 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: PR Submitted A pull request with a fix has been provided.
Projects
None yet
Development

No branches or pull requests

3 participants