Open paulschreiber opened 6 months ago
Yup this is a valid report as the code to fire this warning lives here: https://github.com/facebook/react-native/blob/87692454774d797cd3d7f26a0c31d53a4c90cfdd/packages/community-cli-plugin/src/utils/loadMetroConfig.js#L83-L109
@huntie do you know what might be going on here?
Interesting. @paulschreiber Your Metro config extends expo/metro-config
(rather than @react-native/metro-config
), and is being consumed via React Native Community CLI (rather than Expo CLI which would usually be the target for expo/metro-config
). This will be the cause.
Resolution: I'd suggest copying the template package.json
exactly, and then adding back either 1/ parts of expo/metro-config
as necessary, or 2/ all of expo/metro-config
and placing it 2nd into the mergeConfig
call (shown).
- const { getDefaultConfig } = require('expo/metro-config');
+ const { getDefaultConfig: getExpoDefaultConfig } = require('expo/metro-config');
- const { mergeConfig } = require('@react-native/metro-config');
+ const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
*
* @type {import('metro-config').MetroConfig}
*/
const config = {};
- module.exports = mergeConfig(getDefaultConfig(__dirname), config);
+ module.exports = mergeConfig(getDefaultConfig(__dirname), getExpoDefaultConfig(__dirname), config);
As for whether the warning should happen in this case, if extending expo/metro-config
only — it's correct, but not ideal. We designed the check to be robust by settting a global __REACT_NATIVE_METRO_CONFIG_LOADED
variable, specific to @react-native/metro-config
, with the expectation that this should be loaded in every user's config that inputs to CLI.
The warning will also be removed in future once we are confident people have migrated, likely 0.75.
cc @byCedric — Relevant to decision around expo/metro-config
not directly extending @react-native/metro-config
itself. We can review this, but it's not necessarily the direction we have to go. The above user fix is the valid approach.
@huntie As noted in steps to reproduce, this config file was created by the React Native and Expo scaffolding.
It's unclear from your comment who should make the changes to metro.config.js
(I assume package.json
is a typo).
@paulschreiber Right, this is part of Expo's instructions with npx install-expo-modules@latest
, I see now 👍🏻.
https://docs.expo.dev/bare/installing-expo-modules/#optional-use-expo-cli-for-bundling
I'll follow up with @byCedric.
Where is the React native CLI solution ?
Description
When I start my app locally (
npm run ios
), I get this error:My
metro.config.js
looks like this:Since I am using Expo, I need to extend that, too.
Steps to reproduce
npx install-expo-modules@latest
npm run ios
React Native Version
0.73.4
Affected Platforms
Build - MacOS
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/paulschreiber/metro-config-warning
Screenshots and Videos
No response