Skip to content

[0.87] Bootstrap Metro from InitializeCore until setup-env is graph-reachable#57551

Closed
zeyap wants to merge 1 commit into
0.87-stablefrom
fix-setup-env-bootstrap-0.87
Closed

[0.87] Bootstrap Metro from InitializeCore until setup-env is graph-reachable#57551
zeyap wants to merge 1 commit into
0.87-stablefrom
fix-setup-env-bootstrap-0.87

Conversation

@zeyap

@zeyap zeyap commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Fresh 0.87 projects redbox on launch:

Failed to call into JavaScript module method RCTDeviceEventEmitter.emit().
Module has not been registered as callable.
Registered callable JavaScript modules (n = 1): AppRegistry.

Only AppRegistry is registered as callable — i.e. core initialization never runs.

Root cause (#57475)

Core init runs via Metro's serializer.getModulesRunBeforeMainModule. Metro (metro/src/lib/getAppendScripts.js) only emits the run-before __r() for a module already present in the bundle graph, and silently skips it otherwise:

const paths = [...options.runBeforeMainModule, entryPoint];
for (const path of paths) {
  if (modules.some((module) => module.path === path)) {  // only if already in the graph
    /* __r(moduleId) */
  }
}

#57475 switched the run-before target from Libraries/Core/InitializeCoresrc/setup-env.js.

  • InitializeCore.js is reachable (imported by Libraries/ReactPrivate/ReactNativePrivateInitializeCore.js).
  • src/setup-env.js is imported by nothing → not in the graph → silently skipped → core init never runs.

The two modules are functionally identical (both call setUpDefaultReactNativeEnvironment().default()), so only reachability changed.

Evidence (bundle tail)

Run-before target Bundle tail Boots?
src/setup-env.js (current) __r(0);
Libraries/Core/InitializeCore (this PR) __r(110); __r(0);

Ruled out: Metro cache (cold --reset-cache identical), stale Metro, and #57484 (./src/* exports removal — restoring it did not help).

Scope — interim stopgap

This only reverts the internal Metro bootstrap target back to InitializeCore. It does not touch the public react-native/setup-env entry point or its deprecation of InitializeCore — those ship unchanged.

The proper fix (make setup-env graph-reachable, or make Metro treat getModulesRunBeforeMainModule entries as graph roots) should land on main and supersede this. cc @huntie — this is your setup-env stack; flagging for the durable fix. Note main uses equivalent wiring (its follow-up #57498 is cosmetic — resolves to the same unreachable file), so main is likely affected too.

Changelog

[General][Fixed] - Fix apps failing to boot ("RCTDeviceEventEmitter not registered as callable") caused by core init not running.

Test Plan

  • yarn test-release-local -t RNTestProject -p iOS: app boots without the redbox.
  • Bundle tail contains __r(<InitializeCore>); __r(0); instead of just __r(0);.

…eachable

Summary:
Fresh 0.87 projects redbox on launch with:

  Failed to call into JavaScript module method RCTDeviceEventEmitter.emit().
  Module has not been registered as callable.
  Registered callable JavaScript modules (n = 1): AppRegistry.

Core initialization never runs. Metro's `getModulesRunBeforeMainModule`
(see metro/src/lib/getAppendScripts.js) only emits the run-before `__r()`
call for a module that is *already present in the bundle graph*, and
silently skips it otherwise.

#57475 switched the run-before target from `Libraries/Core/InitializeCore`
to `src/setup-env.js`. `InitializeCore` is reachable in the graph (imported
by `Libraries/ReactPrivate/ReactNativePrivateInitializeCore.js`), but
`src/setup-env.js` is imported by nothing, so Metro skips it and core init
never runs. The two modules are functionally identical (both call
`setUpDefaultReactNativeEnvironment().default()`).

Evidence (bundle tail):
- setup-env target:     `__r(0);`            (broken)
- InitializeCore target: `__r(110); __r(0);`  (fixed)

This is an INTERIM stopgap to unblock the 0.87 RC. It only changes the
internal Metro bootstrap target back to `InitializeCore`; the public
`react-native/setup-env` entry point and its deprecation of InitializeCore
are unchanged. The proper fix (make `setup-env` graph-reachable, or make
Metro treat `getModulesRunBeforeMainModule` entries as graph roots) should
land on main and supersede this.

Changelog:
[General][Fixed] - Fix apps failing to boot ("RCTDeviceEventEmitter not
registered as callable") due to core init not running.

Test Plan:
- `yarn test-release-local -t RNTestProject -p iOS`: app boots without redbox.
- Bundle tail now contains `__r(<InitializeCore>); __r(0);` instead of just `__r(0);`.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 14, 2026
@github-actions

Copy link
Copy Markdown

Caution

Missing Changelog

Please add a Changelog to your PR description. See Changelog format

@zeyap zeyap closed this Jul 14, 2026
@huntie

huntie commented Jul 14, 2026

Copy link
Copy Markdown
Member

(Resolved by reactwg/react-native-releases#1338. #57498 is non-cosmetic — but also this happened to due a race condition/selective picking with #57484.)

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner Pick Request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants