microsoft / react-native-macos

A framework for building native macOS apps with React.
https://microsoft.github.io/react-native-windows/
MIT License
3.39k stars 130 forks source link

[RNTester] Correctly specify React Native dependency #2065

Closed Saadnajmi closed 6 months ago

Saadnajmi commented 6 months ago

Please select one of the following

Summary:

After #2030 landed, running yarn start (an alias of react-native start) in packages/rn-tester leads to this error:

command not found: react-native

This seems to be because Yarn 4 is much stricter about only using declared dependencies as compared to Yarn 1, and RNTester's package.json only specifies react-native as a peer dependency (a "*" at that!):

...
  "peerDependencies": {
    "react": "18.2.0",
    "react-native": "*"
  },
...

What we want is tell RNTester ( a private package that will never be published) to use the workspace copy of react-native, rather than download from NPM. Luckily, modern package managers have the workspace:* syntax for exactly that! Let's update our package.json. I also had to specify react-native-macos as the dependency instead of react-native.

This fix won't work upstream in React Native, where yarn 1 doesn't support workspace:*, and the version needs to update for every nightly / stable release. I have prepared a separate fix there: https://github.com/facebook/react-native/pull/42756

Changelog:

[INTERNAL] [FIXED] - Fix running react-native start in rn-tester with yarn 4

Test Plan:

CI should pass.