Skip to content

Commit

Permalink
Fixed Android cliPath Gradle configuration option for build.gradle (#…
Browse files Browse the repository at this point in the history
…31839)

Summary:
When using monorepo with react-native you need to provide `android/app/build.gradle` following params(`cliPath`):
```
project.ext.react = [
    root: "../../../../",
    cliPath: "../../../../node_modules/react-native/cli.js",
    entryFile: "...",
    hermesCommand: "../../../../node_modules/hermes-engine/%OS-BIN%/hermesc"
]
```

With latest react-native `0.64.2` version you will get:
```
* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command 'node'' finished with non-zero exit value 1
```

Debugging this issue showed that providing `cliPath` options ends up building wrong path to cli:
```
> Task :app:bundleReleaseJsAndAssets FAILED
node:internal/modules/cjs/loader:944
  throw err;
  ^

Error: Cannot find module '/node_modules/react-native/cli.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
    at Function.Module._load (node:internal/modules/cjs/loader:774:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
```

Changed `react.gradle` for proper File creation for `cliPath` to support this configuration option.

## Changelog

[Android] [Fixed] - Changed `react.gradle` `detectCliPath` function logic for `cliPath` case

Pull Request resolved: #31839

Test Plan: Run `./gradlew assembleRelease` or `./gradlew assembleDebug`

Reviewed By: yungsters

Differential Revision: D30877674

Pulled By: sshic

fbshipit-source-id: 26b75f8d29bf26b01630dde576b9052d0b94d89e
  • Loading branch information
vitalyiegorov authored and facebook-github-bot committed Sep 15, 2021
1 parent 05b449b commit ce51b62
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion react.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def detectEntryFile(config) {
*/
def detectCliPath(config) {
if (config.cliPath) {
return config.cliPath
return "${projectDir}/${config.cliPath}"
}
if (new File("${projectDir}/../../node_modules/react-native/cli.js").exists()) {
return "${projectDir}/../../node_modules/react-native/cli.js"
Expand Down

0 comments on commit ce51b62

Please sign in to comment.