react-native-community / cli

The React Native Community CLI - command line tools to help you build RN apps
MIT License
2.4k stars 904 forks source link

ios, macos module conflict. `run-ios` command not working after adding `react-native-macos`. #1747

Closed Aashu-Dubey closed 1 year ago

Aashu-Dubey commented 2 years ago

Environment

System:
    OS: macOS 12.6
    CPU: (8) arm64 Apple M1
    Memory: 97.39 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.1 - /usr/local/bin/node
    Yarn: 1.22.18 - /opt/homebrew/bin/yarn
    npm: 8.6.0 - /opt/homebrew/bin/npm
    Watchman: 2022.10.24.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /Users/username/.rvm/gems/ruby-2.7.5/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0
    Android SDK:
      API Levels: 29, 30, 31, 32
      Build Tools: 28.0.3, 29.0.2, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0
      System Images: android-32 | Google APIs ARM 64 v8a
      Android NDK: Not Found
  IDEs:
    Android Studio: 2021.3 AI-213.7172.25.2113.9014738
    Xcode: 14.0/14A309 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_332 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.1.0 => 18.1.0 
    react-native: 0.70.5 => 0.70.5 
    react-native-macos: ^0.68.0-0 => 0.68.57 
  npmGlobalPackages:
    *react-native*: Not Found

Description

I have encountered conflict between ios and macos platform module if used together while running the npx react-native run-ios command, where run-ios fails to find the workspace file under ios folder after adding macos support using this guide.

Initially when creating a new project or if you're only using default added platforms, it works just fine. but as soon as I add react-native-macos, cli throws this error:

error Could not find Xcode project files in "/Users/username/path/to/project/test_rn_proj/ios" folder.

Note:- I can still run the ios app by opening the ios/test_rn_proj.xcworkspace in xcode and run from there, so the issue is only cli specific.

Reproducible Demo

To reproduce,

  1. you just have to create a new react-native project using command npx react-native init AwesomeProject as specified here (I used the one for typescript template).
  2. Optional:- you can run run-ios command and it'll work fine.
  3. and then add macos, using command npx react-native-macos-init as specified here.
  4. run the run-ios and you'll get above error, while the run-macos works just fine.

Now to check what is causing this issue or whether it is from this cli or from macos one, I did a little debugging, and the error is thrown here, so I added a logger here (in node_modules code) to check the data before and after adding the macos support.

Here's the line for logger to be precise:

_cliTools().logger.info(`ctx.project.ios ${JSON.stringify(ctx.project.ios)}`);

Note:- I checked it on both latest rn version 0.70.5 and 0.68.x (based on the current rn-macos release), and the issue was same.


This is all that I checked, so I'm not sure why it is happening. While it seems the cli is getting correct ios path and other details are also ios specific only.

Maybe cause both ios and macos module create the workspace files with same name?

image

Note:- The command works again as soon as I remove the react-native-macos dependency, even if I don't remove the macos folder, so not sure which one has the issue. But still, I guess if both module are in different folders, it shouldn't create any conflict?

Also I wasn't sure where to report this issue, here or at react-native-macos, but based on above debugging, it seems the issue is here, still let me know if I should report it there.

Based on node_modules/@react-native-community/cli-platform-ios/package.json, the cli version used is 9.2.1.

image

Thank you!

szymonrybczak commented 1 year ago

Hey @Aashu-Dubey, you're using the 9.2.1 version of cli, but react-native-macos is using the 7.0.3, and between these two version some things changed and this causes error. So to make that working you must use older react-native version 😄