Skip to content

Conversation

@ludwig-pro
Copy link

Summary

This PR fixes the installation failure when running npx react-native-macos-init on projects with newer patch versions of React Native.

Problem

When following the official Getting Started guide:

npx @react-native-community/cli init myProject --version 0.79
cd myProject
npx react-native-macos-init

The last command fails with:

Command failed: npm install --save --silent "react-native-macos@^0.79.0-0"

Root Cause

  1. The published react-native-macos@0.79.1 declares an exact peer dependency: "react-native": "0.79.6"
  2. The React Native CLI installs the latest patch version (e.g., react-native@0.79.7)
  3. npm 7+ enforces strict peer dependency checking by default
  4. npm refuses to install due to the version mismatch (0.79.6 vs 0.79.7)
  5. The --silent flag hides the actual error message, making debugging difficult

Solution

Add --legacy-peer-deps to the npm install command. This flag:

  • Makes npm behave like npm 6, ignoring peer dependency version mismatches
  • Is safe for patch version differences (0.79.x) which are backward-compatible by semver convention
  • Does not create duplicate installations of react-native

Changes

  • packages/react-native-macos-init/src/cli.ts: Added --legacy-peer-deps flag to the npm install command

Test Plan

  1. Create a new React Native project: npx @react-native-community/cli init TestApp --version 0.79
  2. Verify that react-native@0.79.7 (or newer patch) is installed
  3. Run npx react-native-macos-init with this fix
  4. Confirm installation succeeds without errors

Related

I'll open a separate issue to discuss using a caret range (^0.79.0) instead of exact versions for the react-native peer dependency in release branches.

npm 7+ enforces strict peer dependency checking by default. When
react-native-macos declares an exact peer dependency (e.g., react-native@0.79.6)
but the user has a newer patch version installed (e.g., react-native@0.79.7),
npm refuses to install the package.

Adding --legacy-peer-deps makes npm behave like npm 6, ignoring peer dependency
version mismatches. This is safe for patch version differences which are
backward-compatible by semver convention.

This fixes the installation error:
Command failed: npm install --save --silent "react-native-macos@^0.79.0-0"
@Saadnajmi
Copy link
Collaborator

Sorry for the delay! We were working very hard on getting 0.81 out the door and I hadn't looked at other PRs.

The strict peer dep is intentional, it's what we use to determine the right version of Hermes to use. So I'm not sure I want to take this fix but also I need to think about what we need to do to our unit flow to fix 🤔

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.

2 participants