react-native-community / cli

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

projectRoot not working as expected #246

Closed brunolemos closed 5 years ago

brunolemos commented 5 years ago

Environment

  React Native Environment Info:
    System:
      OS: macOS 10.14.3
      CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
      Memory: 18.46 MB / 8.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 11.11.0 - /usr/local/bin/node
      Yarn: 1.15.2 - /usr/local/bin/yarn
      npm: 6.9.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5314842
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild

I have the latest @react-native-community/cli 2.x installed globally and react-native 0.59 in the project.

Description

Cannot run react-native run-android ... from the monorepo root.

For iOS it works: react-native run-ios --project-path packages/mobile/ios

Reproducible Demo

react-native run-android --projectRoot packages/mobile/android

error Android project not found. Are you sure this is a React Native project?

Project: https://github.com/brunolemos/react-native-web-monorepo

Esemesek commented 5 years ago

It seems like common flags declared in cliEntry, are not passed properly to commands. This applies to run-android and run-ios. I'll investigate that.

EDIT. Not entirely sure, but it seems like this functionality is broken for a while now.

Esemesek commented 5 years ago

@brunolemos it seems like there is a mismatch between parameters that set root in run-android and run-ios. I was able to make things work in your project by running:

react-native run-android --root packages/mobile

This seems very wrong and counter-intuitive to have different flags between commands. This might work as a temporary solution in your project, but we definitely need to fix that one.

grabbou commented 5 years ago

This is not a bug with projectRoot per se. projectRoot describes the root of the CLI - the folder we should look for node_modules from. It defaults to cwd.

The root inside run-android is equivalent of projectPath inside run-ios. It's to explicitly set the location of the android folder.

Setting projectRoot to packages/mobile/android is not good since this is not really the root of your app.

We should rename root to something more intuitive, e.g. androidAppFolder. I have an open issue to update this command tho to automatically detect android folder location. See issue #143 for details.

brunolemos commented 5 years ago

Yes ideally the cli option should have the same name for both ios and android, don't know if there's any issue tracking this.

grabbou commented 5 years ago

I guess #143 is a good one. I'll make sure to rename it, tho I am planning to make a detection system automatically detect unusual locations.