Skip to content

esbuild serializer causes Gradle to crash when the bundle generates a warning #2416

Closed

Description

What happened?

I configured Metro to use the ESBuild serializer, with the default options.

Using the default react-native-gradle-plugin process, Gradle runs the bundle command when building a release, changed so it runs rnx-bundle:

# app/build.gradle

react {
  bundleCommand = "rnx-bundle"
}

But this happens:

…/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:1:51547: warning: the variable "Promise" was not declared in function "bE1"
[22:52:00]: ▸  use strict";(()=>{var lse=Object.create;var cI=Object.defineProperty;var  [the whole 5 MB bundle]
[This repeated 10 times, including the whole bundle, as there are 10 warnings]
…
Exception in thread "pool-1-thread-1" java.lang.OutOfMemoryError: Java heap space

And then the build fails, because the Java process too all available memory trying to output those 5 MB lines.

If I disable whitespace minification in esbuild, then I each error displays the line where it happens, which are short (as there are newline characters in the emitted bundle), and the build goes fine.

Here is the output with whitespace minification disabled:

> Task :app:createBundleReleaseJsAndAssets
warning: the transform cache was reset.
                Welcome to Metro v0.73.9
              Fast - Scalable - Integrated

info esbuild bundle size: 6619674
info Writing bundle output to:, 
…/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle
info Writing sourcemap output to:, …/android/app/build/intermediates/sourcemaps/react/release/index.android.bundle.packager.map
info Done writing bundle output
info Done writing sourcemap output
info Copying 17 asset files
info Done copying assets
…/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:2495:20: warning: the variable "Promise" was not declared in function "bE1"
    (yE1 || (yE1 = Promise.resolve())).then(e).catch(function(t) {
                   ^~~~~~~
…/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:2496:14: warning: the variable "setTimeout" was not declared in anonymous function " 3#"
      return setTimeout(function() {
             ^~~~~~~~~~
…/android/app/build/ASSETS/createBundleReleaseJsAndAssets/index.android.bundle:3916:17: warning: the variable "FileReader" was not declared in function "Bue"
    var t = new FileReader(), r = kT1(t);

When I launch the bundle directly from the CLI (react-native rnx-bundle --dev false --platform android), those errors are not displayed, so I am not sure what Gradle does that displays them. Could it be a post-process task, done with Metro once the bundle is created?

Affected Package

metro-serializer-esbuild

Version

0.1.23

Which platforms are you seeing this issue on?

  • Android
  • iOS
  • macOS
  • Windows

System Information

info Fetching system and libraries information...
System:
    OS: macOS 13.3.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 67.69 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
    Yarn: Not Found
    npm: 9.5.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
    Watchman: 2023.05.01.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.12.1 - /var/folders/cn/qgvjcjx97mj8rc2vx37vgkvh0000gn/T/frum_69495_1683799833063/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
    Android SDK:
      API Levels: 26, 31, 32, 33
      Build Tools: 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0, 33.0.0, 33.0.2
      System Images: android-24 | Google APIs ARM 64 v8a, android-25 | Google APIs ARM 64 v8a, android-26 | ARM 64 v8a, android-26 | Google APIs ARM 64 v8a, android-28 | Google ARM64-V8a Play ARM 64 v8a, android-32 | Google APIs ARM 64 v8a
      Android NDK: Not Found
  IDEs:
    Android Studio: 2022.1 AI-221.6008.13.2211.9477386
    Xcode: 14.3/14E222b - /usr/bin/xcodebuild
  Languages:
    Java: 20.0.1 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: ^18.2.0 => 18.2.0
    react-native: ^0.71.8 => 0.71.8
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to Reproduce

  • Configure a project to use metro-serializer-esbuild (changing the Metro config is enough, no need for @rnx-kit/cli here)
  • Have warnings in your bundle
  • Run ./gradlew bundleRelease to generate release
  • Check the build output, there is a huge line with the whole bundle when showing the warning location. Gradle may even crash if your bundle is big enough.

Code of Conduct

  • I agree to follow this project's Code of Conduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfeature: cliThis is related to CLIupstreamThis should be fixed/reported upstream

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions