Skip to content

Conversation

@mfazekas
Copy link
Contributor

@mfazekas mfazekas commented Jul 8, 2024

Fixes: #45307

Changelog:

[Android] [Fixed] - if npx @react-native-community/cli config fails or timeouts proper error is shown and built is aborted, instead of leaving and empty autolinking.json

Summary

During build npx @react-native-community/cli config is generated into autolinking.json. When command fails, we should error and should not leave and empty autolinking.json

Test Plan

Output of the reproducer in #45307 looks like this:

android % ./gradlew assembleDebug
Starting a Gradle Daemon (subsequent builds will be faster)
ERROR: autolinkLibrariesFromCommand: Failed to create /Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/build/generated/autolinking/autolinking.json - process npx @react-native-community/cli config  exited with error code: 126

FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/settings.gradle' line: 3

* What went wrong:
A problem occurred evaluating settings 'android'.
> ERROR: autolinkLibrariesFromCommand: Failed to create /Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/build/generated/autolinking/autolinking.json - process npx @react-native-community/cli config  exited with error code: 126

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 10s
8 actionable tasks: 4 executed, 4 up-to-date

Output if you modify the package.json to be invalid looks like this:

android % ./gradlew assembleDebug
ERROR: autolinkLibrariesFromCommand: process npx @react-native-community/cli config  exited with error code: 1
JSONError: JSON Error in /Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/package.json: 

  35 |     "node": ">=18"
  36 |   },
> 37 |   SOMETHING_NON_JSON
     |   ^
  38 |   "packageManager": "[email protected]",
  39 |   "resolutions": {
  40 |     "rtn-centered-text": "portal:../RTNCenteredText"

Unexpected token "S" (0x53) in JSON at position 1019 while parsing near "...ode\": \">=18\"\n  },\n  SOMETHING_NON_JSON\n ..." 

  35 |     "node": ">=18"
  36 |   },
> 37 |   SOMETHING_NON_JSON
     |   ^
  38 |   "packageManager": "[email protected]",
  39 |   "resolutions": {
  40 |     "rtn-centered-text": "portal:../RTNCenteredText"

    at parseJson (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/parse-json/index.js:29:21)
    at loadJson (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/@react-native-community/cli-config/node_modules/cosmiconfig/dist/loaders.js:48:16)
    at #loadConfiguration (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/@react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:116:36)
    at #loadConfigFileWithImports (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/@react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:87:54)
    at #readConfiguration (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/@react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:84:82)
    at search (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/@react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:50:63)
    at emplace (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/@react-native-community/cli-config/node_modules/cosmiconfig/dist/util.js:36:20)
    at ExplorerSync.search (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/@react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:78:42)
    at getUserDefinedOptionsFromMetaConfig (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/@react-native-community/cli-config/node_modules/cosmiconfig/dist/index.js:32:37)
    at mergeOptionsBase (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/@react-native-community/cli-config/node_modules/cosmiconfig/dist/index.js:60:31)


FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/settings.gradle' line: 3

* What went wrong:
A problem occurred evaluating settings 'android'.
> ERROR: autolinkLibrariesFromCommand: process npx @react-native-community/cli config  exited with error code: 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 2s
8 actionable tasks: 4 executed, 4 up-to-date

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Jul 8, 2024
Copy link
Contributor

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Can we make the CI green @mfazekas ?

@mfazekas mfazekas force-pushed the autolink-error-handling branch 3 times, most recently from a460b91 to e5c1116 Compare July 9, 2024 18:20
@analysis-bot
Copy link

analysis-bot commented Jul 9, 2024

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 21,285,119 -15,285
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 24,481,981 -15,510
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: b4b6614
Branch: main

@mfazekas mfazekas requested a review from cortinico July 9, 2024 19:07
@mfazekas
Copy link
Contributor Author

mfazekas commented Jul 9, 2024

Thanks for the PR. Can we make the CI green @mfazekas ?

@cortinico sorry, my bad should be fixed now, along with suggestions in review

@cortinico
Copy link
Contributor

@cortinico sorry, my bad should be fixed now, along with suggestions in review

Yup I've left just a follow up comment and then we can merge this 👍

@mfazekas mfazekas force-pushed the autolink-error-handling branch 3 times, most recently from 32ddf13 to 8708d0e Compare July 10, 2024 11:51
@mfazekas mfazekas force-pushed the autolink-error-handling branch from 8708d0e to 313d65e Compare July 10, 2024 12:07
@facebook-github-bot
Copy link
Contributor

@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@cortinico merged this pull request in 3782511.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jul 11, 2024
@github-actions
Copy link

This pull request was successfully merged by @mfazekas in 3782511.

When will my fix make it into a release? | How to file a pick request?

blakef pushed a commit that referenced this pull request Jul 15, 2024
…n zero exit code (#45333)

Summary:
Fixes: #45307

## Changelog:

[Android] [Fixed] - if `npx react-native-community/cli config` fails or timeouts proper error is shown and built is aborted, instead of leaving and empty autolinking.json

During build `npx react-native-community/cli config` is generated into autolinking.json. When command fails, we should error and should not leave and empty `autolinking.json`

Pull Request resolved: #45333

Test Plan:
Output of the reproducer in #45307 looks like this:

```log
android % ./gradlew assembleDebug
Starting a Gradle Daemon (subsequent builds will be faster)
ERROR: autolinkLibrariesFromCommand: Failed to create /Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/build/generated/autolinking/autolinking.json - process npx react-native-community/cli config  exited with error code: 126

FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/settings.gradle' line: 3

* What went wrong:
A problem occurred evaluating settings 'android'.
> ERROR: autolinkLibrariesFromCommand: Failed to create /Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/build/generated/autolinking/autolinking.json - process npx react-native-community/cli config  exited with error code: 126

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 10s
8 actionable tasks: 4 executed, 4 up-to-date
```

Output if you modify the package.json to be invalid looks like this:

```log
android % ./gradlew assembleDebug
ERROR: autolinkLibrariesFromCommand: process npx react-native-community/cli config  exited with error code: 1
JSONError: JSON Error in /Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/package.json:

  35 |     "node": ">=18"
  36 |   },
> 37 |   SOMETHING_NON_JSON
     |   ^
  38 |   "packageManager": "[email protected]",
  39 |   "resolutions": {
  40 |     "rtn-centered-text": "portal:../RTNCenteredText"

Unexpected token "S" (0x53) in JSON at position 1019 while parsing near "...ode\": \">=18\"\n  },\n  SOMETHING_NON_JSON\n ..."

  35 |     "node": ">=18"
  36 |   },
> 37 |   SOMETHING_NON_JSON
     |   ^
  38 |   "packageManager": "[email protected]",
  39 |   "resolutions": {
  40 |     "rtn-centered-text": "portal:../RTNCenteredText"

    at parseJson (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/parse-json/index.js:29:21)
    at loadJson (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/loaders.js:48:16)
    at #loadConfiguration (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:116:36)
    at #loadConfigFileWithImports (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:87:54)
    at #readConfiguration (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:84:82)
    at search (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:50:63)
    at emplace (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/util.js:36:20)
    at ExplorerSync.search (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/ExplorerSync.js:78:42)
    at getUserDefinedOptionsFromMetaConfig (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/index.js:32:37)
    at mergeOptionsBase (/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/node_modules/react-native-community/cli-config/node_modules/cosmiconfig/dist/index.js:60:31)

FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/boga/Work/OSS/RNMBGL/rn-fabric-boolattribute/ReproducerApp/android/settings.gradle' line: 3

* What went wrong:
A problem occurred evaluating settings 'android'.
> ERROR: autolinkLibrariesFromCommand: process npx react-native-community/cli config  exited with error code: 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 2s
8 actionable tasks: 4 executed, 4 up-to-date
```

Reviewed By: cipolleschi

Differential Revision: D59582430

Pulled By: cortinico

fbshipit-source-id: bedb9563175cc5c46f5af80cf309769e56b803cc
@migueldaipre
Copy link
Collaborator

Hey guys @mfazekas @cortinico, does this fix support monorepos projects?

I'd like to try to help.

I get the following error:


FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/migueldaipre/Desktop/Projects/bitcoinly/apps/mobile/android/settings.gradle' line: 3

* What went wrong:
A problem occurred evaluating settings 'android'.
> ERROR: autolinkLibrariesFromCommand: process npx @react-native-community/cli config exited with error code: 126

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 2s

My settings.gradle file

pluginManagement { includeBuild("../../../node_modules/@react-native/gradle-plugin") }
plugins { id("com.facebook.react.settings") }
extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() }
rootProject.name = 'Bitcoinly'
include ':app'
includeBuild('../../../node_modules/@react-native/gradle-plugin')

@migueldaipre
Copy link
Collaborator

If I run

npx @react-native-community/cli config

I receive

sh: /Users/migueldaipre/Desktop/Projects/bitcoinly/node_modules/.bin/rnc-cli: Permission denied

@cortinico
Copy link
Contributor

Hey guys @mfazekas @cortinico, does this fix support monorepos projects?

Yes it should. @migueldaipre please open a separate issue and provide a reproducer of your repo setup. Ultimately, you should be able to invoke npx @react-native-community/cli config in your monorepo. If the invocation of config is different, you can customize it inside the settings.gradle file

@mfazekas
Copy link
Contributor Author

@migueldaipre

sh: /Users/migueldaipre/Desktop/Projects/bitcoinly/node_modules/.bin/rnc-cli: Permission denied

I saw this too, that lead to this PR, but wasn't able to reproduce after nuking the. node_modules and yarn install again. This fix doesn't address rnc-cli: Permission denied, but if it does happen, codegen should behave correctly, report correct error, and not create an empty auto linking.json .

@migueldaipre
Copy link
Collaborator

After I ran chmod +x /Users/migueldaipre/Desktop/Projects/bitcoinly/node_modules/.bin/rnc-cli it's sync correctly again.

@Immacio
Copy link

Immacio commented Aug 20, 2024

rm-rf node_modules and re-install packages, this fixed the issue for me after a recent upgrade to 0.75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0.75-rc.3: autolink should handle failures in rnc/cli config

6 participants