Skip to content

@rnx-kit/metro-config causes warning on react-native 0.72 #2481

@tido64

Description

@tido64

What happened?

In a vanilla project with react-native 0.72 and only @rnx-kit/metro-config, react-native bundle outputs the following warning:

warn From React Native 0.72, your metro.config.js file should extend'@react-native/metro-config'. Please see the React Native 0.72 changelog, or copy the template at:
https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js

@rnx-kit/metro-config correctly loads defaults from @react-native/metro-config, but the CLI cannot know this. This is currently how it checks whether someone is loading defaults from the correct package, by scanning metro.config.js for any mention of "@react-native/metro-config": https://github.com/react-native-community/cli/blob/3569633e1bbda4858195feb8537d7b9969b2040e/packages/cli-plugin-metro/src/tools/loadMetroConfig.ts#L100-L104

As a workaround, we can simply mention the package in a comment like below:

diff --git a/packages/test-app/metro.config.js b/packages/test-app/metro.config.js
index 0a8bd04a..8a976d89 100644
--- a/packages/test-app/metro.config.js
+++ b/packages/test-app/metro.config.js
@@ -1,3 +1,6 @@
+// Just mentioning "@react-native/metro-config" here to prevent CLI from warning
+// about missing `@rnx-kit/metro-config` and falling back to internal defaults.
+
 const { exclusionList, makeMetroConfig } = require("@rnx-kit/metro-config");
 const MetroSymlinksResolver = require("@rnx-kit/metro-resolver-symlinks");

Affected Package

@rnx-kit/metro-config

Version

1.3.7

Which platforms are you seeing this issue on?

  • Android
  • iOS
  • macOS
  • Windows

System Information

n/a

Steps to Reproduce

  1. Bump react-native to 0.72 (and make sure metro 0.76 is used)
  2. In packages/test-app, bundle with CLI, e.g.: yarn react-native bundle --entry-file src/index.ts --platform android --dev true --bundle-output dist/main.android.jsbundle --assets-dest dist/res

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfeature: metroThis is related to MetroupstreamThis should be fixed/reported upstream

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions