@@ -69,15 +69,46 @@ We recommend using Expo CLI and related tooling configurations to bundle your ap
6969+ presets: ['babel-preset-expo'],
7070```
7171
72- #### Extend expo/metro-config in your metro.config.js
72+ #### Extend expo/metro-config in your metro.config.js and resolve react-native-macos
7373
7474``` diff metro.config.js
7575- const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
76- + const { getDefaultConfig } = require('expo/metro-config');
77- + const { mergeConfig } = require('@react-native/metro-config');
76+ + const {getDefaultConfig} = require('expo/metro-config');
7877
7978 /**
8079 * Metro configuration
80+
81+ - const config = {};
82+ + const config = getDefaultConfig(__dirname);
83+
84+ - module.exports = mergeConfig(getDefaultConfig(__dirname), config);
85+ + config.resolver.resolveRequest = (context, moduleName, platform) => {
86+ + if (
87+ + platform === 'macos' &&
88+ + (moduleName === 'react-native' || moduleName.startsWith('react-native/'))
89+ + ) {
90+ + const newModuleName = moduleName.replace(
91+ + 'react-native',
92+ + 'react-native-macos',
93+ + );
94+ + return context.resolveRequest(context, newModuleName, platform);
95+ + }
96+ + return context.resolveRequest(context, moduleName, platform);
97+ + };
98+ +
99+ + const originalGetModulesRunBeforeMainModule =
100+ + config.serializer.getModulesRunBeforeMainModule;
101+ + config.serializer.getModulesRunBeforeMainModule = () => {
102+ + try {
103+ + return [
104+ + require.resolve('react-native/Libraries/Core/InitializeCore'),
105+ + require.resolve('react-native-macos/Libraries/Core/InitializeCore'),
106+ + ];
107+ + } catch {}
108+ + return originalGetModulesRunBeforeMainModule();
109+ + };
110+ +
111+ + module.exports = config;
81112```
82113
83114#### Configure macOS project to bundle with Expo CLI
@@ -127,6 +158,12 @@ And add support the `"main"` field in **package.json** by making the following c
127158 #endif
128159```
129160
161+ Finally, to start the Metro bundler using Expo CLI, run: ` npx expo start ` or replace your existing ` start ` command in ` package.json ` :
162+
163+ ``` diff package.json
164+ - "start": "react-native start",
165+ + "start": "expo start",
166+ ```
130167
131168## Usage
132169
0 commit comments