Skip to content

Commit 2765a4c

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. 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 6c5b9b1 commit 2765a4c

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ function getCommunityCliDefaultConfig(
5858
return {
5959
resolver,
6060
serializer: {
61-
// We can include multiple copies of setup-env here because Metro will
61+
// We can include multiple copies of InitializeCore here because metro will
6262
// only add ones that are already part of the bundle
6363
getModulesRunBeforeMainModule: () => [
64-
require.resolve('react-native/setup-env', {
64+
require.resolve('react-native/Libraries/Core/InitializeCore', {
6565
paths: [ctx.root],
6666
}),
6767
...outOfTreePlatforms.map(platform =>
6868
require.resolve(
69-
`${ctx.platforms[platform].npmPackageName}/setup-env`,
69+
`${ctx.platforms[platform].npmPackageName}/Libraries/Core/InitializeCore`,
7070
{paths: [ctx.root]},
7171
),
7272
),

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: Overridden in community-cli-plugin
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)