Skip to content

Commit 1683b12

Browse files
Kudokelset
authored andcommitted
add InitializeCore in getModulesRunBeforeMainModule (#38207)
Summary: the `IntializeCore` is critical to react-native for setup polyfills. without this, we would have some erros like undefined `global.performance`. since the effort is now proposing `react-native/metro-config` as universal metro-config, it is better to have the `IntializeCore` in it. we ran into issues when using expo-cli in bare react-native projects. it happens when using [the default metro config](https://github.com/facebook/react-native/blob/5f84d7338f42fe9b1d5bf2a9b1c8321b59551f15/packages/react-native/template/metro.config.js) and starting metro server without the react-native-community-cli. ### Why the issue does not happen on `yarn react-native start`? when using `yarn react-native start`, the react-native-community-cli will merge its internal metro-config with the `InitializeCore` ([https://github.com/facebook/react-native/issues/1](https://github.com/react-native-community/cli/blob/5d8a8478cd104adf4a4dd34c09c2e256325ae61d/packages/cli-plugin-metro/src/commands/start/runServer.ts#L56), [https://github.com/facebook/react-native/issues/2](https://github.com/react-native-community/cli/blob/e8e7402512da8c3fbbc58a195284ef0008c7491f/packages/cli-plugin-metro/src/tools/loadMetroConfig.ts#L51-L61)). that's why the issue doesn't happen on react-native-community-cli. ## Changelog: [GENERAL][FIXED] - `global.performance` in undefined when starting metro from Expo CLI Pull Request resolved: #38207 Test Plan: ```sh $ npx react-native init RN072 --version 0.72 $ cd RN072 $ yarn add expo $ npx expo run:ios # then it hits the exception because the global.performance is undefined. ``` Reviewed By: rshest Differential Revision: D47257439 Pulled By: huntie fbshipit-source-id: ae294e684047e503d674f0c72563b56d1803ba36
1 parent e163a13 commit 1683b12

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

packages/metro-config/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ function getDefaultConfig(
4646
unstable_conditionNames: ['require', 'import', 'react-native'],
4747
},
4848
serializer: {
49+
// Note: This option is overridden in cli-plugin-metro (getOverrideConfig)
50+
getModulesRunBeforeMainModule: () => [
51+
require.resolve('react-native/Libraries/Core/InitializeCore'),
52+
],
4953
getPolyfills: () => require('@react-native/js-polyfills')(),
5054
},
5155
server: {

0 commit comments

Comments
 (0)