Skip to content

Consider using caret range for react-native peer dependency #2786

@ludwig-pro

Description

@ludwig-pro

Summary

The react-native peer dependency in published react-native-macos packages uses an exact version (e.g., "react-native": "0.79.6") instead of a caret range (e.g., "react-native": "^0.79.0"). This causes installation failures with newer patch versions.

Problem

When following the Getting Started guide, users get:

npx @react-native-community/cli init myProject --version 0.79
cd myProject
npx react-native-macos-init
# Error: Command failed: npm install --save --silent "react-native-macos@^0.79.0-0"

Why This Happens

  1. npx @react-native-community/cli init --version 0.79 installs the latest 0.79.x version (currently 0.79.7)
  2. react-native-macos@0.79.1 declares "peerDependencies": { "react-native": "0.79.6" } (exact version)
  3. npm 7+ enforces strict peer dependency checking and refuses to install

Suggested Solution

Use a caret range for the react-native peer dependency when creating releases:

{
  "peerDependencies": {
    "react-native": "^0.79.0"
  }
}

Benefits

  • Accepts all patch versions (0.79.0, 0.79.1, ..., 0.79.7, etc.)
  • Follows semver convention (patch versions are backward-compatible)
  • Avoids installation failures when users have newer patches
  • No need for --legacy-peer-deps workaround

Current Workaround

PR #2785 adds --legacy-peer-deps to the CLI as an immediate fix.

Related

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions