Skip to content

Every Android release bundle empties the machine-wide Metro cache (--reset-cache) #59543

Open

Description

@YevheniiKotyrlo

Description

The Gradle plugin bundles every Android release with --reset-cache: BundleHermesCTask.getBundleCommand adds it unconditionally, and neither extraPackagerArgs nor the Metro config can drop it. Metro's default cache root is machine-wide, os.tmpdir()/metro-cache, so createBundleReleaseJsAndAssets in one app empties the transform cache that every other Metro on the machine uses — another project's dev server, another app's release build. A release bundle that empties it while another Metro writes into it fails:

:app:createBundleReleaseJsAndAssets FAILED
error ENOTEMPTY, Directory not empty: 'C:\Users\<user>\AppData\Local\Temp\metro-cache\18'

#52275 asked why the flag is always set and was closed as stale.

Expected: a release bundle leaves other bundlers' cache entries alone, or the app can opt out of --reset-cache.

Steps to reproduce

  1. Clone the reproducer (the template app on 0.88.1) and run yarn in ReproducerApp.
  2. Leave an entry in Metro's cache root, as another bundler would: mkdir -p "$TMPDIR/metro-cache/00" && echo x > "$TMPDIR/metro-cache/00/entry-from-another-bundler" (on Windows, %TEMP%).
  3. cd android && ./gradlew :app:createBundleReleaseJsAndAssets.
  4. The entry is gone: the task ran bundle --platform android --dev false --reset-cache --entry-file index.js, and metro-cache holds only this bundle's entries.

Expected: the release bundle leaves Metro's cache to the bundlers that share it, and the other bundler's entry stays.
Actual: the entry is gone (step 4).

React Native Version

0.88.1

Affected Platforms

Build - Windows

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

System:
  OS: Windows 11 10.0.26300
  CPU: "(32) x64 AMD Ryzen 9 9950X3D 16-Core Processor          "
  Memory: 159.74 GB / 255.67 GB
Binaries:
  Node:
    version: 26.12.1
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 1.22.22
    path: C:\Users\<user>\AppData\Roaming\npm\yarn.CMD
  npm:
    version: 12.2.1
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK:
    API Levels:
      - "33"
      - "35"
      - "35"
      - "35"
      - "36"
      - "37"
    Build Tools:
      - 35.0.0
      - 36.0.0
      - 36.1.0
      - 37.0.0
    System Images:
      - android-26 | Google APIs Intel x86_64 Atom
      - android-28 | Google APIs Intel x86_64 Atom
      - android-29 | Google APIs Intel x86_64 Atom
      - android-30 | Google APIs Intel x86_64 Atom
      - android-31 | Google APIs Intel x86_64 Atom
      - android-32 | Google APIs Intel x86_64 Atom
      - android-33 | Google APIs Intel x86_64 Atom
      - android-34 | Google APIs Intel x86_64 Atom
      - android-35 | Google APIs Intel x86_64 Atom
      - android-36.1 | Google Play Intel x86_64 Atom
      - android-36.1 | Pre-Release 16 KB Page Size Google Play Intel x86_64 Atom
      - android-37.0 | Google APIs Intel x86_64 Atom
    Android NDK: Not Found
  Windows SDK: Not Found
IDEs:
  Android Studio: AI-262.9437.185.2621.16467767
  Visual Studio: Not Found
Languages:
  Java:
    version: 17.0.20.1
    path: C:\Program Files\Microsoft\jdk-17.0.20.101-hotspot\bin\javac.EXE
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 20.2.0
    wanted: 20.2.0
  react:
    installed: 19.3.0
    wanted: 19.3.0
  react-native:
    installed: 0.88.1
    wanted: 0.88.1
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Stacktrace or Logs

== before the bundle task
<tmpdir>/metro-cache/00/entry-from-another-bundler
> Task :app:createBundleReleaseJsAndAssets
cmd /c node node_modules\react-native\cli.js bundle --platform android --dev false --reset-cache --entry-file index.js --bundle-output android\app\build\generated\assets\react\release\index.android.bundle --assets-dest android\app\build\generated\res\react\release …
BUILD SUCCESSFUL in 1m 55s
== after the bundle task
the other bundler's entry is gone
files under <tmpdir>/metro-cache now: 533

MANDATORY Reproducer

https://github.com/YevheniiKotyrlo/rn-release-bundle-resets-metro-cache

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