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

@babel/plugin-proposal-decorators is not supported in hermes-parser - was: Broken babel preset setup with @babel/plugin-proposal-decorators and React Native 0.76.0 #1549

Closed
lucaswitch opened this issue Oct 25, 2024 · 11 comments
Assignees

Comments

@lucaswitch
Copy link

Description

Since i upgraded from react-native 0.75.4 to 0.76 and the babel plugin "@babel/plugin-proposal-decorators" stopped working.

What we know:

I was not able to fix the issue by changing babel or @babel/plugin-proposal-decorators versions so probably is not something with babel setup.
I can confirm that brand new react-native 0.76.0 can not work with @babel/plugin-proposal-decorators as we can see on the reproducer.

The reproducer is a standard react-native 0.76.0 with "@babel/plugin-proposal-decorators": "^7.25.9" and a babel.config.js that i believe most of the users configure.
The reproducer can be found on:
https://github.com/lucaswitch/broken-babel-preset

I understand that it's not a problem of react-native project but is something that we can probably can be adjusted on the official babel preset.
Actually this plugin is used by a lot of developers including me and a lot of libraries need that configuration to be able to be used on a react-native project.

Steps to reproduce

I tested this issue only on IOS but i think it's not related to any platform since is a babel related problem.

I'm not a babel expert but i suspect there is something on @react-native/babel-preset that broke this configuration.
Created a little repro with a brand new bare react-native project and an small minimal decorator setup just to prove that is not transforming js syntax the right way on react-native.

Screenshot 2024-10-25 at 16 26 09

React Native Version

0.76.0

Affected Platforms

Runtime - iOS

Output of npx react-native info

System:
  OS: macOS 14.0
  CPU: (24) x64 Intel(R) Xeon(R) CPU E5-2670 v3 @ 2.30GHz
  Memory: 30.60 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.10.0
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.19
    path: /usr/local/bin/yarn
  npm:
    version: 10.9.0
    path: /usr/local/bin/npm
  Watchman:
    version: 2024.10.21.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23339.11.2421.12483815
  Xcode:
    version: 15.1/15C65
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /usr/local/opt/openjdk@17/bin/javac
  Ruby:
    version: 3.3.5
    path: /usr/local/opt/ruby/bin/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
    wanted: 0.76.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

ERROR  SyntaxError in index.js: unrecognized character '@' (16:2)
  @readonly
  ^
 (NOBRIDGE) ERROR  [Error: TransformError SyntaxError in index.js: unrecognized character '@' (16:2)

Reproducer

https://github.com/lucaswitch/broken-babel-preset

Screenshots and Videos

Screenshot 2024-10-25 at 16 34 59

@cortinico cortinico changed the title Broken babel preset setup with @babel/plugin-proposal-decorators and latest version 0.76.0 @babel/plugin-proposal-decorators is not supported in hermes-parser - was: Broken babel preset setup with @babel/plugin-proposal-decorators and React Native 0.76.0 Oct 25, 2024
@cortinico cortinico transferred this issue from facebook/react-native Oct 25, 2024
@lucaswitch
Copy link
Author

Is that something to be fixed or unsupported?
From my point of view react-native should be able to work with all 7.x Babel plugins.

@cipolleschi
Copy link

cipolleschi commented Oct 29, 2024

Thanks for the issue. We are discussing how to proceed forward internally. We made some changes in the JS parsers and the new one does not support all the Babel plugins, especially the ones that are still in a proposal stage (like the decorators one, which is in stage 3).

@lucaswitch would you be able to work around this, for the time being?

@lucaswitch
Copy link
Author

Thanks for the issue. We are discussing how to proceed forward internally. We made some changes in the JS parsers and the new one does not support all the Babel plugins, especially the ones that are still in a proposal stage (like the decorators one, which is in stage 3).

@lucaswitch would you be able to work around this, for the time being?

Not at all, actually i had to revert the apps to 0.75.4.
We are still searching a workaround on the rn babel preset to work through this.

We're using that to define schemas on https://github.com/Nozbe/WatermelonDB which is the goto solution for offline first apps on react-native right now.

@huntie huntie self-assigned this Oct 29, 2024
@huntie
Copy link
Member

huntie commented Oct 31, 2024

@lucaswitch Working on a fix, where we can opt out JS files without // @flow to use the base Babel parser.

Workaround: For now, please convert files that need this extended syntax to TypeScript (.ts(x)).

@lucaswitch
Copy link
Author

Thats awesome!
I'll do that!

huntie added a commit to huntie/hermes that referenced this issue Oct 31, 2024
Summary:
This is a mitigation for facebook#1549.

Updates `babel-plugin-syntax-hermes-parser` to abort when the file contents do not include `flow`.

**Context: React Native**

Originally changed in facebook/react-native#46696, as our internal Flow support had diverged from `babel/plugin-syntax-flow` (facebook/react-native#46601).

We effectively have three flavours of JavaScript in support:
- Flow@latest for the `react-native` package, shipped as source — uses `hermes-parser`.
- TypeScript for product code (community template, Expo) — uses `babel/plugin-syntax-typescript`.
- Plain JavaScript/JSX in product code, *which may be extended with additional user Babel plugins and needs lenient parsing* — uses base `babel/parser` (**this change**).

I'd love to simplify this 😅.

Differential Revision: D65272155
huntie added a commit to huntie/react-native that referenced this issue Oct 31, 2024
Summary:
Motivated by facebook/hermes#1549. This was originally changed in facebook#46696, as our internal Flow support had diverged from `babel/eslint-parser` (facebook#46601).

We effectively have three flavours of JavaScript in support:
- Flow@latest for the `react-native` package, shipped as source — uses `hermes-parser`.
- TypeScript for product code (community template, Expo) — uses `babel/plugin-syntax-typescript`.
- Plain JavaScript or Flow in product code, *which may be extended with additional user Babel plugins and needs lenient parsing* — uses `babel/plugin-syntax-flow` via `babel/eslint-parser` (**this change**).

I'd love to simplify this 😅.

Switching to `hermes-eslint` for the RN monorepo codebase (D63541483) is unchanged.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D65272156
huntie added a commit to huntie/hermes that referenced this issue Oct 31, 2024
Summary:

This is a mitigation for facebook#1549.

Updates `babel-plugin-syntax-hermes-parser` to abort when the file contents do not include `flow`.

**Context: React Native**

Originally changed in facebook/react-native#46696, as our internal Flow support had diverged from `babel/plugin-syntax-flow` (facebook/react-native#46601).

We effectively have three flavours of JavaScript in support:
- Flow@latest for the `react-native` package, shipped as source — uses `hermes-parser`.
- TypeScript for product code (community template, Expo) — uses `babel/plugin-syntax-typescript`.
- Plain JavaScript/JSX in product code, *which may be extended with additional user Babel plugins and needs lenient parsing* — uses base `babel/parser` (**this change**).

I'd love to simplify this 😅.

Reviewed By: cipolleschi

Differential Revision: D65272155
huntie added a commit to huntie/hermes that referenced this issue Oct 31, 2024
Summary:

This is a mitigation for facebook#1549.

Updates `babel-plugin-syntax-hermes-parser` to abort when the file contents do not include `flow`.

**Context: React Native**

Originally changed in facebook/react-native#46696, as our internal Flow support had diverged from `babel/plugin-syntax-flow` (facebook/react-native#46601).

We effectively have three flavours of JavaScript in support:
- Flow@latest for the `react-native` package, shipped as source — uses `hermes-parser`.
- TypeScript for product code (community template, Expo) — uses `babel/plugin-syntax-typescript`.
- Plain JavaScript/JSX in product code, *which may be extended with additional user Babel plugins and needs lenient parsing* — uses base `babel/parser` (**this change**).

I'd love to simplify this 😅.

Reviewed By: robhogan, cipolleschi

Differential Revision: D65272155
huntie added a commit to huntie/hermes that referenced this issue Nov 1, 2024
Summary:

This is a mitigation for facebook#1549.

Updates `babel-plugin-syntax-hermes-parser` to abort when the file contents do not include `flow`.

**Context: React Native**

Originally changed in facebook/react-native#46696, as our internal Flow support had diverged from `babel/plugin-syntax-flow` (facebook/react-native#46601).

We effectively have three flavours of JavaScript in support:
- Flow@latest for the `react-native` package, shipped as source — uses `hermes-parser`.
- TypeScript for product code (community template, Expo) — uses `babel/plugin-syntax-typescript`.
- Plain JavaScript/JSX in product code, *which may be extended with additional user Babel plugins and needs lenient parsing* — uses base `babel/parser` (**this change**).

I'd love to simplify this 😅.

Differential Revision: D65272155
huntie added a commit to huntie/hermes that referenced this issue Nov 1, 2024
Summary:

This is a mitigation for facebook#1549.

Updates `babel-plugin-syntax-hermes-parser` to abort when the file contents do not include `flow`.

**Context: React Native**

Originally changed in facebook/react-native#46696, as our internal Flow support had diverged from `babel/plugin-syntax-flow` (facebook/react-native#46601).

We effectively have three flavours of JavaScript in support:
- Flow@latest for the `react-native` package, shipped as source — uses `hermes-parser`.
- TypeScript for product code (community template, Expo) — uses `babel/plugin-syntax-typescript`.
- Plain JavaScript/JSX in product code, *which may be extended with additional user Babel plugins and needs lenient parsing* — uses base `babel/parser` (**this change**).

I'd love to simplify this 😅.

Differential Revision: D65272155
facebook-github-bot pushed a commit to facebook/react-native that referenced this issue Nov 1, 2024
Summary:
Pull Request resolved: #47333

Motivated by facebook/hermes#1549. This was originally changed in #46696, as our internal Flow support had diverged from `babel/eslint-parser` (#46601).

We effectively have three flavours of JavaScript in support:
- Flow@latest for the `react-native` package, shipped as source — uses `hermes-parser`.
- TypeScript for product code (community template, Expo) — uses `babel/plugin-syntax-typescript`.
- Plain JavaScript or Flow in product code, *which may be extended with additional user Babel plugins and needs lenient parsing* — uses `babel/plugin-syntax-flow` via `babel/eslint-parser` (**this change**).

I'd love to simplify this 😅.

Switching to `hermes-eslint` for the RN monorepo codebase (D63541483) is unchanged.

Changelog: [Internal]

Reviewed By: robhogan, cipolleschi

Differential Revision: D65272156

fbshipit-source-id: 3a2bbe3fcf8ed6057f6d994a0be4985e6bf46fa9
huntie added a commit to huntie/hermes that referenced this issue Nov 1, 2024
Summary:

This is a mitigation for facebook#1549.

Updates `babel-plugin-syntax-hermes-parser` to abort when the file contents do not include `flow`.

**Context: React Native**

Originally changed in facebook/react-native#46696, as our internal Flow support had diverged from `babel/plugin-syntax-flow` (facebook/react-native#46601).

We effectively have three flavours of JavaScript in support:
- Flow@latest for the `react-native` package, shipped as source — uses `hermes-parser`.
- TypeScript for product code (community template, Expo) — uses `babel/plugin-syntax-typescript`.
- Plain JavaScript/JSX in product code, *which may be extended with additional user Babel plugins and needs lenient parsing* — uses base `babel/parser` (**this change**).

I'd love to simplify this 😅.

Differential Revision: D65272155
huntie added a commit to huntie/hermes that referenced this issue Nov 4, 2024
Summary:

This is a mitigation for facebook#1549.

Updates `babel-plugin-syntax-hermes-parser` to abort when the file contents do not include `flow`.

**Context: React Native**

Originally changed in facebook/react-native#46696, as our internal Flow support had diverged from `babel/plugin-syntax-flow` (facebook/react-native#46601).

We effectively have three flavours of JavaScript in support:
- Flow@latest for the `react-native` package, shipped as source — uses `hermes-parser`.
- TypeScript for product code (community template, Expo) — uses `babel/plugin-syntax-typescript`.
- Plain JavaScript/JSX in product code, *which may be extended with additional user Babel plugins and needs lenient parsing* — uses base `babel/parser` (**this change**).

I'd love to simplify this 😅.

Reviewed By: vzaidman

Differential Revision: D65272155
huntie added a commit to huntie/hermes that referenced this issue Nov 5, 2024
Summary:

This is a mitigation for facebook#1549.

Updates `babel-plugin-syntax-hermes-parser` to abort when the file contents do not include `flow`.

**Context: React Native**

Originally changed in facebook/react-native#46696, as our internal Flow support had diverged from `babel/plugin-syntax-flow` (facebook/react-native#46601).

We effectively have three flavours of JavaScript in support:
- Flow@latest for the `react-native` package, shipped as source — uses `hermes-parser`.
- TypeScript for product code (community template, Expo) — uses `babel/plugin-syntax-typescript`.
- Plain JavaScript/JSX in product code, *which may be extended with additional user Babel plugins and needs lenient parsing* — uses base `babel/parser` (**this change**).

I'd love to simplify this 😅.

Differential Revision: D65272155
facebook-github-bot pushed a commit that referenced this issue Nov 6, 2024
Summary:
Pull Request resolved: #1556

This is a mitigation for #1549.

Updates `babel-plugin-syntax-hermes-parser` to include a new `parseLangTypes` option, which we will configure in React Native's Babel preset to abort when the file contents do not include `flow`.

**Context: React Native**

Originally changed in facebook/react-native#46696, as our internal Flow support had diverged from `babel/plugin-syntax-flow` (facebook/react-native#46601).

We effectively have three flavours of JavaScript in support:
- Flow@latest for the `react-native` package, shipped as source — uses `hermes-parser`.
- TypeScript for product code (community template, Expo) — uses `babel/plugin-syntax-typescript`.
- Plain JavaScript/JSX in product code, *which may be extended with additional user Babel plugins and needs lenient parsing* — uses base `babel/parser` (**this change**).

I'd love to simplify this 😅.

Reviewed By: pieterv

Differential Revision: D65272155

fbshipit-source-id: b3be10410962ffffd4e0d483d10fe88d865c0783
huntie added a commit to huntie/react-native that referenced this issue Nov 12, 2024
Summary:
Resolves facebook/hermes#1549.

Changelog:
[General][Fixed] - When using Babel with plain JavaScript files, support for additional user syntax plugins should be fixed (now uses Babel's parser instead of hermes-parser). There is no change for JS files annotated with `flow`, where extended JS syntax remains unsupported.

Differential Revision: D65816797
huntie added a commit to huntie/react-native that referenced this issue Nov 12, 2024
Summary:
Pull Request resolved: facebook#47568

Resolves facebook/hermes#1549.

Changelog:
[General][Fixed] - When using Babel with plain JavaScript files, support for additional user syntax plugins should be fixed (now uses Babel's parser instead of hermes-parser). There is no change for JS files annotated with `flow`, where extended JS syntax remains unsupported.

Differential Revision: D65816797
facebook-github-bot pushed a commit that referenced this issue Nov 14, 2024
Summary:
Original Author: [email protected]
Original Git: f2970e7
Original Reviewed By: pieterv
Original Revision: D65272155

Pull Request resolved: #1556

This is a mitigation for #1549.

Updates `babel-plugin-syntax-hermes-parser` to include a new `parseLangTypes` option, which we will configure in React Native's Babel preset to abort when the file contents do not include `flow`.

**Context: React Native**

Originally changed in facebook/react-native#46696, as our internal Flow support had diverged from `babel/plugin-syntax-flow` (facebook/react-native#46601).

We effectively have three flavours of JavaScript in support:
- Flow@latest for the `react-native` package, shipped as source — uses `hermes-parser`.
- TypeScript for product code (community template, Expo) — uses `babel/plugin-syntax-typescript`.
- Plain JavaScript/JSX in product code, *which may be extended with additional user Babel plugins and needs lenient parsing* — uses base `babel/parser` (**this change**).

I'd love to simplify this 😅.

Reviewed By: mattbfb

Differential Revision: D65787624

fbshipit-source-id: b06f1499b2d02462777ac72f03d8bb5c713b0a19
@robhogan
Copy link
Contributor

As of 0.76.2, Babel syntax plugins including @babel/plugin-proposal-decorators should work (including for non-TypeScript) when:

  • Files are not annotated with @flow.
  • metro.config.js is configured with transformer.hermesParser==false (we're considering changing this default in a patch release).
// metro.config.js

/**
 * Metro configuration
 * https://reactnative.dev/docs/metro
 *
 * @type {import('metro-config').MetroConfig}
 */
const config = {
    transformer: {
        hermesParser: false,
    },
};

@yuezonglun
Copy link

yuezonglun commented Nov 15, 2024 via email

@huntie
Copy link
Member

huntie commented Nov 18, 2024

Shipped in React Native 0.76.2 (please update all @react-native/* dependencies in-line!), see @robhogan's comment above.

@huntie huntie closed this as completed Nov 18, 2024
facebook-github-bot pushed a commit to facebook/react-native that referenced this issue Nov 18, 2024
…nfig (#47670)

Summary:

Now that we have `babel-plugin-syntax-hermes-parser` in `react-native/babel-preset` (since D63535216), it's no longer necessary to use `hermes-parser` directly in Metro in order to use newer Flow syntax.

Babel with `babel-plugin-syntax-hermes-parser` is generally preferable, because it intelligently falls back to parsing with Babel for any non-`flow` files.

See facebook/hermes#1549 for context.

Changelog:
[General][Fixed] metro-config: Don't use `hermes-parser` by default, prefer `babel-plugin-syntax-hermes-parser`, which supports other syntax plugins.

Differential Revision: D66002056
facebook-github-bot pushed a commit to facebook/react-native that referenced this issue Nov 19, 2024
…nfig (#47670)

Summary:
Pull Request resolved: #47670

Now that we have `babel-plugin-syntax-hermes-parser` in `react-native/babel-preset` (since D63535216), it's no longer necessary to use `hermes-parser` directly in Metro in order to use newer Flow syntax.

Babel with `babel-plugin-syntax-hermes-parser` is generally preferable, because it intelligently falls back to parsing with Babel for any non-`flow` files.

See facebook/hermes#1549 for context.

Changelog:
[General][Fixed] metro-config: Don't use `hermes-parser` by default, prefer `babel-plugin-syntax-hermes-parser`, which supports other syntax plugins.

Reviewed By: huntie

Differential Revision: D66002056

fbshipit-source-id: cf48acec347e2c0791872f8ca4b53f5f8af1c783
@MarlonAEC
Copy link

MarlonAEC commented Nov 20, 2024

@robhogan I have a little problem here if I set the hermesParser: false I got this error:

Error: Got unexpected undefined
    at nullthrows (/Users/maespinosa/Documents/mobile-app/client/node_modules/nullthrows/nullthrows.js:7:15)
    at Graph._recursivelyCommitModule (/Users/maespinosa/Documents/mobile-app/client/node_modules/metro/src/DeltaBundler/Graph.js:197:27)
    at Graph._addDependency (/Users/maespinosa/Documents/mobile-app/client/node_modules/metro/src/DeltaBundler/Graph.js:297:25)
    at Graph._recursivelyCommitModule (/Users/maespinosa/Documents/mobile-app/client/node_modules/metro/src/DeltaBundler/Graph.js:242:16)
    at Graph._addDependency (/Users/maespinosa/Documents/mobile-app/client/node_modules/metro/src/DeltaBundler/Graph.js:297:25)
    at Graph._recursivelyCommitModule (/Users/maespinosa/Documents/mobile-app/client/node_modules/metro/src/DeltaBundler/Graph.js:242:16)
    at Graph._addDependency (/Users/maespinosa/Documents/mobile-app/client/node_modules/metro/src/DeltaBundler/Graph.js:297:25)
    at Graph._recursivelyCommitModule (/Users/maespinosa/Documents/mobile-app/client/node_modules/metro/src/DeltaBundler/Graph.js:242:16)
    at Graph.traverseDependencies (/Users/maespinosa/Documents/mobile-app/client/node_modules/metro/src/DeltaBundler/Graph.js:99:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Unfortunately changing all the affected files from *.js -> *.ts(x) is not an option because we just started the migration to typescript a few months ago and there is still a HUGE chuck of work pending to be refactored. This is my metro config:

const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');

const defaultConfig = getDefaultConfig(__dirname);
const { assetExts, sourceExts } = defaultConfig.resolver;

/**
 * Metro configuration
 * https://reactnative.dev/docs/metro
 *
 * @type {import('metro-config').MetroConfig}
 */
const config = {
    transformer: {
        babelTransformerPath: require.resolve('react-native-svg-transformer'),
        hermesParser: false,
    },
    resolver: {
        assetExts: assetExts.filter((ext) => ext !== "svg"),
        sourceExts: [...sourceExts, 'svg', 'cjs'],
    },
};

module.exports = mergeConfig(defaultConfig, config);

and this is my babel.config.js

module.exports = function (api) {
    api.cache(true);

    const presets = ['module:@react-native/babel-preset'];
    const plugins = [
        ['@babel/plugin-proposal-decorators', { version: "legacy" }],
        'react-native-reanimated/plugin',
    ];

    return {
        presets,
        plugins,
    };
};

Any suggestions on how to tackle this? BTW by just removing hermesParser I get this error:

SyntaxError in App.js: unrecognized character '@' (252:4)
    @autobind

and before you ask this is my libraries versions:

"react-native": "^0.76.2",
"@react-native/babel-preset": "^0.76.2",
"@react-native/eslint-config": "^0.76.2",
"@react-native/metro-config": "^0.76.2",
"@react-native/typescript-config": "^0.76.2",

Should I consider rolling back to a previous version of React Native? If so, which version is the correct one to avoid this problem? Thanks in advance!

@robhogan
Copy link
Contributor

Hi @MarlonAEC - that looks like a Metro bug probably unrelated to Hermes parser, but maybe you’re encountering it because your build is getting further.

Can you reproduce it with code you can share? If so I’d be keen to take a closer look, this is a new one - a new issue over at https://github.com/facebook/metro would be the best place.

facebook-github-bot pushed a commit to facebook/react-native that referenced this issue Nov 21, 2024
Summary:
Pull Request resolved: #47568

Resolves facebook/hermes#1549.

Changelog:
[General][Fixed] - When using Babel with plain JavaScript files, support for additional user syntax plugins should be fixed (now uses Babel's parser instead of hermes-parser). There is no change for JS files annotated with `flow`, where extended JS syntax remains unsupported.

Reviewed By: blakef

Differential Revision: D65816797

fbshipit-source-id: 9f05e86019548ac8727ee65c2e2c417d78a406d8
@c100k
Copy link

c100k commented Nov 26, 2024

As of 0.76.2, Babel syntax plugins including @babel/plugin-proposal-decorators should work (including for non-TypeScript) when:

* Files are _not_ annotated with `@flow`.

* `metro.config.js` is configured with `transformer.hermesParser==false` (we're considering changing this default in a patch release).
// metro.config.js

/**
 * Metro configuration
 * https://reactnative.dev/docs/metro
 *
 * @type {import('metro-config').MetroConfig}
 */
const config = {
    transformer: {
        hermesParser: false,
    },
};

Side note for those landing here like I did : I also had to set hermesParser: false to overcome the error invalid property name - must be a string, number or identifier\nstatic { MyClass_1 = this; } even if '@babel/plugin-transform-class-static-block' was properly configured and called before the other class-related transformers.

blakef pushed a commit to facebook/react-native that referenced this issue Dec 4, 2024
Summary:
Pull Request resolved: #47333

Motivated by facebook/hermes#1549. This was originally changed in #46696, as our internal Flow support had diverged from `babel/eslint-parser` (#46601).

We effectively have three flavours of JavaScript in support:
- Flow@latest for the `react-native` package, shipped as source — uses `hermes-parser`.
- TypeScript for product code (community template, Expo) — uses `babel/plugin-syntax-typescript`.
- Plain JavaScript or Flow in product code, *which may be extended with additional user Babel plugins and needs lenient parsing* — uses `babel/plugin-syntax-flow` via `babel/eslint-parser` (**this change**).

I'd love to simplify this 😅.

Switching to `hermes-eslint` for the RN monorepo codebase (D63541483) is unchanged.

Changelog: [Internal]

Reviewed By: robhogan, cipolleschi

Differential Revision: D65272156

fbshipit-source-id: 3a2bbe3fcf8ed6057f6d994a0be4985e6bf46fa9
blakef pushed a commit to facebook/react-native that referenced this issue Dec 4, 2024
…nfig (#47670)

Summary:
Pull Request resolved: #47670

Now that we have `babel-plugin-syntax-hermes-parser` in `react-native/babel-preset` (since D63535216), it's no longer necessary to use `hermes-parser` directly in Metro in order to use newer Flow syntax.

Babel with `babel-plugin-syntax-hermes-parser` is generally preferable, because it intelligently falls back to parsing with Babel for any non-`flow` files.

See facebook/hermes#1549 for context.

Changelog:
[General][Fixed] metro-config: Don't use `hermes-parser` by default, prefer `babel-plugin-syntax-hermes-parser`, which supports other syntax plugins.

Reviewed By: huntie

Differential Revision: D66002056

fbshipit-source-id: cf48acec347e2c0791872f8ca4b53f5f8af1c783
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants