fix(mobile): pre-generate worklets output so EAS builds can bundle
Production iOS builds have never succeeded. The Bundle JavaScript phase dies with:
Failed to get the SHA-1 for: .../react-native-worklets/.worklets/<hash>.js
Root cause
The worklets Babel plugin (Bundle Mode, used by react-native-streamdown) writes .worklets/<hash>.js into node_modules/react-native-worklets/ during transform and emits imports pointing at them. Metro snapshots its file map at startup, so a file created mid-transform isn't in the map and getOrComputeSha1 throws.
Locally the files persist in node_modules, so only the first run after a wipe is affected — which is why this looked fine to everyone. EAS installs fresh on every build, so its first bundle always loses the race.
Two details that made this confusing:
- Metro's transform cache suppresses the plugin on warm runs. Retrying without
--clearwrites nothing at all, so the obvious "just run it twice" fix silently does nothing. With--clear, one pass wrote 507 files. - Each pass fails on a different hash. It converges gradually rather than all at once, which is how long-lived local checkouts accumulate the full set (a sibling worktree here had 524).
Fix
An eas-build-post-install hook runs bounded throwaway exports to populate .worklets before the real bundle step. It never fails the build — if it doesn't converge, the real bundle step reports the genuine error rather than this one masking it.
Verification
Wiped .worklets down to the shipped dummy.md to simulate a fresh EAS install, then:
- Hook converged on pass 3 in 48s, producing 510 files.
- The exact command EAS runs —
expo export:embed --eager --platform ios --dev false— then produced a 16MB bundle with no error.
Cost is ~50s of build time.
Note
This is pre-existing and unrelated to the recent Expo batch alignment (#6455) or the carousel fix (#6449); the last green iOS build was a July simulator build on the e2e-test profile, which skips this phase. A cleaner long-term fix would be upstream (Metro learning about transform-time file creation) or dropping Bundle Mode, but this unblocks builds without touching either.
Summary by cubic
Pre-generates react-native-worklets Bundle Mode output during EAS iOS builds so Metro can resolve imports and complete bundling. Previously, production iOS bundles failed because the plugin wrote .worklets/<hash>.js during transform after Metro snapshotted its file map; now we warm those files first, trading ~50s build time for reliable bundles.
Review and rollout
- Adds
eas-build-post-installinapps/mobile/package.jsonto runscripts/warm-worklets.sh. - The script runs up to 4
expo exportpasses for iOS (first with--clear) to populatenode_modules/react-native-worklets/.worklets, then exits success even if not converged; the real bundle step surfaces any genuine errors. - Expected effect: EAS iOS bundling succeeds; Android and local dev unchanged.
- You can tune passes via
WORKLETS_WARMUP_ATTEMPTS.
Summary by CodeRabbit
- Build Improvements
- Improved iOS build preparation by pre-generating required animation and worklet artifacts after cloud builds.
- Added automatic retries and cleanup to make this preparation more reliable without affecting the main build process.