Skip to content

fix: don't require @react-native-community/cli at config-load time#2973

Open
gabrieldonadel wants to merge 2 commits into
microsoft:mainfrom
gabrieldonadel:@gabrieldonadel/rnc-optional-peer
Open

fix: don't require @react-native-community/cli at config-load time#2973
gabrieldonadel wants to merge 2 commits into
microsoft:mainfrom
gabrieldonadel:@gabrieldonadel/rnc-optional-peer

Conversation

@gabrieldonadel
Copy link
Copy Markdown

Summary:

In theory, @react-native-community/cli should be an optional dependency, but currently the runMacOS commands import requires @react-native-community/cli directly, causing Expo CLI users to also have to install @react-native-community/cli

This PR guards the require the same way as the platform packages, and only attaches the commands when the import succeeds. The runtime behavior for projects that do install the CLI is unchanged.

Test Plan:

  • In a project that does not depend on @react-native-community/cli (e.g. an Expo app using expo-modules-autolinking), run pod install and confirm use_native_modules! no longer throws when loading react-native.config.js.
  • In a project that depends on @react-native-community/cli, confirm npx react-native run-macos and the other macOS commands still register and work as before.
  • With DEBUG=* set, confirm the new warning (./local-cli/runMacOS/runMacOS not found, the react-native.config.js may be unusable.) is emitted only when the require fails, matching the existing warnings for the other platform packages.

@gabrieldonadel gabrieldonadel requested a review from a team as a code owner June 3, 2026 19:43
@gabrieldonadel gabrieldonadel force-pushed the @gabrieldonadel/rnc-optional-peer branch from ac26ba8 to 5a73ee1 Compare June 3, 2026 19:57
@Saadnajmi Saadnajmi requested a review from tido64 June 3, 2026 23:08
@gabrieldonadel gabrieldonadel force-pushed the @gabrieldonadel/rnc-optional-peer branch from 5a73ee1 to a20e0ac Compare June 4, 2026 04:24
Comment on lines +94 to +99
} catch {
if (verbose) {
console.warn(
'@react-native-community/cli not found, the react-native.config.js may be unusable.',
);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we log the actual error message instead? There are several things that can go wrong inside runMacOS.

We should also add a comment about Expo here otherwise the next person will not know why we have this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants