Problem
Currently when starting a development server with npm start a warning is produced:
❯ npm start
> new.expensify@9.0.31-12 start
> npx react-native start
warn =================================================================================================
warn From React Native 0.73, your project's Metro config should extend '@react-native/metro-config'
warn or it will fail to build. Please copy the template at:
warn https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js
warn This warning will be removed in future (https://github.com/facebook/metro/issues/1018).
warn =================================================================================================
info Welcome to React Native v0.75
info Starting dev server on port 8081...
▒▒▓▓▓▓▒▒
▒▓▓▓▒▒░░▒▒▓▓▓▒
▒▓▓▓▓░░░▒▒▒▒░░░▓▓▓▓▒
▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓
▓▓░░░░░▒▓▓▓▓▓▓▒░░░░░▓▓
▓▓░░▓▓▒░░░▒▒░░░▒▓▒░░▓▓
▓▓░░▓▓▓▓▓▒▒▒▒▓▓▓▓▒░░▓▓
▓▓░░▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░▓▓
▓▓▒░░▒▒▓▓▓▓▓▓▓▓▒░░░▒▓▓
▒▓▓▓▒░░░▒▓▓▒░░░▒▓▓▓▒
▒▓▓▓▒░░░░▒▓▓▓▒
▒▒▓▓▓▓▒▒
Welcome to Metro v0.80.3
Fast - Scalable - Integrated
It’s because current config uses getDefaultConfig function expo/metro-config which doesn’t assign __REACT_NATIVE_METRO_CONFIG_LOADED property on global object which is then checked inside @react-native/community-cli-plugin package, if not presented the warning is produced.
Solution
Suggested solution from Metro team is to use a getDefaultConfg function from @react-native/metro-config package to extend the config which provides default values for Metro config.
Diff to solve this issue inside metro.config.js file:
@@ -1,10 +1,13 @@
-const {getDefaultConfig} = require('expo/metro-config');
+const {getDefaultConfig: getExpoDefaultConfig} = require('expo/metro-config');
+const {getDefaultConfig: getReactNativeDefaultConfig} = require('@react-native/metro-config');
+
const {mergeConfig} = require('@react-native/metro-config');
const defaultAssetExts = require('metro-config/src/defaults/defaults').assetExts;
const defaultSourceExts = require('metro-config/src/defaults/defaults').sourceExts;
require('dotenv').config();
-const defaultConfig = getDefaultConfig(__dirname);
+const defaultConfig = getReactNativeDefaultConfig(__dirname);
+const expoConfig = getExpoDefaultConfig(__dirname);
const isE2ETesting = process.env.E2E_TESTING === 'true';
const e2eSourceExts = ['e2e.js', 'e2e.ts', 'e2e.tsx'];
@@ -23,4 +26,4 @@ const config = {
},
};
-module.exports = mergeConfig(defaultConfig, config);
+module.exports = mergeConfig(defaultConfig, expoConfig, config);
Provided solution also keeps values and properties from default config from expo/metro-config package. By merging them in relevant order we keep the same behavior with proper config creation.
Problem
Currently when starting a development server with
npm starta warning is produced:It’s because current config uses
getDefaultConfigfunctionexpo/metro-configwhich doesn’t assign__REACT_NATIVE_METRO_CONFIG_LOADEDproperty onglobalobject which is then checked inside@react-native/community-cli-pluginpackage, if not presented the warning is produced.Solution
Suggested solution from Metro team is to use a
getDefaultConfgfunction from@react-native/metro-configpackage to extend the config which provides default values for Metro config.Diff to solve this issue inside
metro.config.jsfile:Provided solution also keeps values and properties from default config from
expo/metro-configpackage. By merging them in relevant order we keep the same behavior with proper config creation.