Skip to content

Fails to determine project configuration #854

Closed

Description

@Glinkis

I'm trying to run react native in a monorepo, and if I run the project with the old 2.9 version, I can run in development mode, if I override the native_modules.gradle-file like this:

-    def command = "node ./node_modules/react-native/cli.js config"
+    def command = "../../node_modules/react-native/cli.js config"

As well as run react-native start in my mobile folder, and run-android in my root folder in a separate terminal window.

But then can't build for production, due to it not finding the node_modules/react-native/cli.js-file when I run with the --variant=release flag.

Now I've upgraded to version 3.0.1 of the @react-native-community/cli package, And added a configuration file in my root folder like so:

// react-native.config.js
module.exports = {
  project: {
    android: {
      sourceDir: './packages/mobile/android',
    },
    ios: {
      project: './packages/mobile/ios/mobile.xcodeproj',
    },
  },
}

Then I run yarn react-native run-android --root packages/mobile from root.
However, it keeps complaining about my configuration.

React Native CLI failed to determine Android project configuration. This is likely due to misconfiguration. Config output: <config output>

If I run react-native config in my root directory, this is what I get:

{
  "root": "C:\\Users\\glink\\Documents\\projects\\my-project",
  "reactNativePath": "C:\\Users\\glink\\Documents\\projects\\my-project\\node_modules\\react-native",
  "dependencies": {},
  "commands": [<commands omittted for brevity>],
  "assets": [],
  "platforms": {
    "ios": {},
    "android": {}
  },
  "haste": {
    "providesModuleNodeModules": [
      "react-native"
    ],
    "platforms": [
      "ios",
      "android"
    ]
  },
  "project": {
    "ios": {
      "sourceDir": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\ios",
      "folder": "C:\\Users\\glink\\Documents\\projects\\my-project",
      "pbxprojPath": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\ios\\mobile.xcodeproj\\project.pbxproj",
      "podfile": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\ios\\Podfile",
      "podspecPath": null,
      "projectPath": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\ios\\mobile.xcodeproj",
      "projectName": "mobile.xcodeproj",
      "libraryFolder": "Libraries",
      "sharedLibraries": [],
      "plist": [],
      "scriptPhases": []
    },
    "android": {
      "sourceDir": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\android",
      "isFlat": true,
      "folder": "C:\\Users\\glink\\Documents\\projects\\my-project",
      "stringsPath": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\android\\src\\main\\res\\values\\strings.xml",
      "manifestPath": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\android\\app\\src\\main\\AndroidManifest.xml",
      "buildGradlePath": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\android\\build.gradle",
      "settingsGradlePath": "C:\\Users\\glink\\Documents\\projects\\my-project\\android\\settings.gradle",
      "assetsPath": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\android\\src\\main\\assets",
      "mainFilePath": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\android\\src\\main\\java\\com\\mobile\\MainApplication.java",
      "packageName": "com.mobile"
    }
  }
}

Activity

  1. added
    question
    on Nov 18, 2019
  2. grabbou commented on Nov 19, 2019

    @grabbou
    Member

    Hey,

    I know this may be confusing, but run-android doesn't use the react-native config yet. That's what @thymikee is working on in his PR: #791. It has its own historical resolution mechanism and that's why it doesn't take into account your paths.

    I would recommend you to drop custom React Native configuration and just run the CLI from within packages/mobile folder instead. This is the standard/recommended approach and also supports multiple React Native apps living side by side.

    So cd ./packages/mobile && yarn react-native run-ios should get you there.

  3. Glinkis commented on Nov 19, 2019

    @Glinkis
    Author

    @grabbou
    Thanks for the response. I cannot run yarn react-native run-android from within my ./packages/mobile-folder, as react native can then not find the command run-android.

    What I have to do is run yarn react-native start from my mobile folder, and yarn react-native run-android --root ./packages/mobile from the root folder.

    I've already written this in the original question, though I realize it might be slightly confusing with all the different conditions.

  4. grabbou commented on Nov 24, 2019

    @grabbou
    Member

    Thanks for the response. I cannot run yarn react-native run-android from within my ./packages/mobile-folder, as react-native can then not find the command run-android.

    Can you make sure that your ./packages/mobile/package.json lists react-native as a dependency?

    In CLI 3.x, it's entirely decoupled from Android and iOS. That way, other platforms, such as Windows, can integrate in an easier way.

    Now, the CLI detects the presence of a platform by looking up your package.json for projects. For example, if you have a react-native dependency listed in your package.json, the CLI will open up this package and load additional commands dynamically, in this case, run-ios and run-android.

    You can see how react-native defines additional commands in this file: https://github.com/facebook/react-native/blob/master/react-native.config.js

    PS. If you have react-native dependency on the root, I recommend moving it down to every package that depends on React Native. Don't worry, Yarn will de-dupe them anyway and hoist.

  5. sibelius commented on Nov 26, 2019

    @sibelius
    Member

    I've solved like this on native_modules.gradle

    - def command = "${npx} --quiet --no-install react-native config"
    + def command = "yarn --silent react-native config"
    ` ``
  6. bviebahn commented on Dec 2, 2019

    @bviebahn

    Solved it by deleting the entries in yarn.lock as described here:
    https://github.com/react-native-community/cli#updating-the-cli

  7. grabbou commented on Jan 13, 2020

    @grabbou
    Member

    Closing due to lack of response from OP. Will reopen if needed. We're going to remove npx at all anyway (in my experience, yarn works better, but we're gonna go for package manager-agnostic solution).

    #886

  8. joshuapinter commented on Feb 4, 2021

    @joshuapinter

    In our case, we have an atypical structure since we added React Native to an existing Android application years ago. After changing the main app/module name to app and moving the entire Android application into a android sub directory, things started to work without an issue.

    I'm sure you could configure things to make the non-standard structure work, which we were doing previously, but with the advent of autolinking, the extra hoop jumping didn't feel warranted. So we caved to the defaults and are moving forward now.

  9. LiangRenDev commented on Feb 8, 2021

    @LiangRenDev

    I have met the same issue, solved it by yarn install, I think this is caused by I use npm install, anyway I think it is caused by wrong version of react-native-community

  10. DevineDecrypter commented on Jul 1, 2021

    @DevineDecrypter

    is there a way to add android tv as a platform in the react-native-video's platforms?

    module.exports = {
      assets: ['./assets/fonts'],
      dependencies: {
        'react-native-video': {
          platforms: {
            android: {
              sourceDir: '../node_modules/react-native-video/android-exoplayer',
            },
          },
        },
      },
    };
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions