Skip to content

Commit 42c1c46

Browse files
committed
[0.87] Bootstrap Metro from InitializeCore until setup-env is graph-reachable
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);`.
1 parent d7288bd commit 42c1c46

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

packages/community-cli-plugin/src/utils/loadMetroConfig.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,16 @@ function getCommunityCliDefaultConfig(
6060
return {
6161
resolver,
6262
serializer: {
63-
// We can include multiple copies of setup-env here because Metro will
63+
// We can include multiple copies of InitializeCore here because metro will
6464
// only add ones that are already part of the bundle
6565
getModulesRunBeforeMainModule: () => [
66-
// NOTE: ctx.reactNativePath is an absolute path, therefore we need to
67-
// reference setup-env.js here by exact path specifier.
68-
require.resolve(path.join(ctx.reactNativePath, 'src/setup-env.js'), {
69-
paths: [ctx.root],
70-
}),
66+
require.resolve(
67+
path.join(ctx.reactNativePath, 'Libraries/Core/InitializeCore'),
68+
{paths: [ctx.root]},
69+
),
7170
...outOfTreePlatforms.map(platform =>
7271
require.resolve(
73-
`${ctx.platforms[platform].npmPackageName}/setup-env`,
72+
`${ctx.platforms[platform].npmPackageName}/Libraries/Core/InitializeCore`,
7473
{paths: [ctx.root]},
7574
),
7675
),

packages/metro-config/src/index.flow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function getDefaultConfig(projectRoot: string): ConfigT {
6161
serializer: {
6262
// Note: This option is overridden in cli-plugin-metro (getOverrideConfig)
6363
getModulesRunBeforeMainModule: () => [
64-
require.resolve('react-native/setup-env'),
64+
require.resolve('react-native/Libraries/Core/InitializeCore'),
6565
],
6666
getPolyfills: () => require('@react-native/js-polyfills')(),
6767
isThirdPartyModule({path: modulePath}: Readonly<{path: string, ...}>) {

0 commit comments

Comments
 (0)