Skip to content

@react-native/babel-preset fails on class static blocks: "Static class blocks are not enabled" #59853

Open

Description

@trackoor

Description

@react-native/babel-preset enables the class-features plugins (transform-private-methods / transform-private-property-in-object in the Hermes profiles, transform-class-properties in default) but not @babel/plugin-transform-class-static-block. Those plugins throw on a class static { } block (ES2022), so any app file or dependency that contains one breaks the bundle. babel-preset-expo added the plugin for this reason (expo/expo#37495).

Steps to reproduce

  1. Take the reproducer template (RN 0.88.1) and add a class with a static block to App.tsx:
class Config {
  static value = 0;
  static {
    Config.value = 2;
  }
}
  1. Run npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output out.js.

The bundle fails (see logs). Expected: it builds and Config.value is 2.

Same error with Babel directly, on 0.88.1 and on 0.90.0-nightly-20261107-3aed1720f:

const babel = require('@babel/core');

babel.transformSync('class A { static { globalThis.out = 2; } }', {
  filename: 'a.js',
  babelrc: false,
  configFile: false,
  presets: ['@react-native/babel-preset'],
});

React Native Version

0.88.1

Affected Platforms

Build - Linux

Output of npx @react-native-community/cli info

System:
  OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
  CPU: (64) x64 Intel(R) Xeon(R) CPU @ 2.80GHz
Binaries:
  Node:
    version: 26.13.0
  npm:
    version: 11.20.0
npmPackages:
  "@react-native-community/cli":
    installed: 20.2.0
  react:
    installed: 19.3.0
  react-native:
    installed: 0.88.1
Android:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

error App.tsx: /.../ReproducerApp/App.tsx: Static class blocks are not enabled. Please add `@babel/plugin-transform-class-static-block` to your configuration.
  13 | } from 'react-native-safe-area-context';
  14 |
> 15 | class Config {
     | ^
  16 |   static value = 0;
  17 |   static {
  18 |     Config.value = 2;

MANDATORY Reproducer

https://github.com/trackoor/react-native-class-static-block-repro

Screenshots and Videos

n/a

Credit: https://ucsbplse.github.io/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions