Skip to content

Commit

Permalink
add InitializeCore in getModulesRunBeforeMainModule (#38207)
Browse files Browse the repository at this point in the history
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` ([#1, [#2). 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
  • Loading branch information
Kudo authored and facebook-github-bot committed Jul 7, 2023
1 parent f071616 commit 0ccbd65
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/metro-config/index.js
Expand Up @@ -49,6 +49,10 @@ function getDefaultConfig(
unstable_conditionNames: ['require', 'import', 'react-native'],
},
serializer: {
// Note: This option is overridden in cli-plugin-metro (getOverrideConfig)
getModulesRunBeforeMainModule: () => [
require.resolve('react-native/Libraries/Core/InitializeCore'),
],
getPolyfills: () => require('@react-native/js-polyfills')(),
},
server: {
Expand Down

0 comments on commit 0ccbd65

Please sign in to comment.