react-native-community / cli

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

Yarn workspaces w/ Symlinks Breaks CLI Config with Exit Code 236 #2512

Closed brianlenz closed 1 month ago

brianlenz commented 1 month ago

Environment

$ npx react-native info
info Fetching system and libraries information...
System:
  OS: macOS 14.6.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 155.97 MB / 64.00 GB
  Shell:
    version: 5.2.26
    path: /opt/homebrew/bin/bash
Binaries:
  Node:
    version: 18.20.3
    path: /opt/homebrew/bin/node
  Yarn:
    version: 4.5.0
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.7.0
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2024.06.17.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/brian/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK:
    API Levels:
      - "29"
      - "30"
      - "31"
      - "33"
      - "34"
    Build Tools:
      - 26.0.2
      - 26.0.3
      - 28.0.3
      - 29.0.2
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 31.0.0
      - 31.0.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
    System Images:
      - android-29 | Google APIs ARM 64 v8a
      - android-29 | Google Play ARM 64 v8a
      - android-30 | Google Play ARM 64 v8a
      - android-31 | Google Play ARM 64 v8a
      - android-33 | Desktop ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.19072.14.2412.12360217
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /opt/homebrew/opt/openjdk@17/bin/javac
  Ruby:
    version: 3.3.0
    path: /Users/brian/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.75.3
    wanted: 0.75.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Description

After upgrading to RN 0.75.3 and RN CLI 14.1.0, we found that Android builds were failing. We are using RN in a monorepo with Yarn workspaces. The issue appears to be related to having symlinks in other workspaces within the same monorepo. I was able to create a simple repro repo that shows the issue. You can reproduce the issue two ways:

  1. npx @react-native-community/cli config
    Error: ENOTDIR: not a directory, open '.../rncli-symlink-bug/scripts/script-a/src/index.js/package.json'
  2. ./gradlew clean

    ERROR: autolinkLibrariesFromCommand: process npx @react-native-community/cli config exited with error code: 236
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Settings file '.../rncli-symlink-bug/testsymlinkproj/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: 236

This appears to be similar to #2490 and #2498, but none of the solutions there work.

Reproducible Demo

git clone git@github.com:brianlenz/rncli-symlink-bug.git
cd rncli-symlink-bug/
yarn install
cd testsymlinkproj/
npx @react-native-community/cli config # this will error with: Error: ENOTDIR: not a directory, open '.../rncli-symlink-bug/scripts/script-a/src/index.js/package.json'
cd android/
./gradlew clean # this will error with: ERROR: autolinkLibrariesFromCommand: process npx @react-native-community/cli config exited with error code: 236

The only way to fix the issue is to remove the symlink that is triggering the error (which shouldn't be necessary, of course):

# from the root of the rncli-symlink-bug project
rm scripts/script-a/src/index.js

Then, if you try again, the commands will work. The CLI needs to be fixed to properly handle/ignore these symlinks.

kbqdev commented 1 month ago

+1 same

scottsoif commented 1 month ago

Same issue. please help with this

brianlenz commented 1 month ago

It's possible this is actually an issue with npx. I've seen the same issue running npx with other commands (e.g. npx @react-native-vector-icons/codemod) 🤔 I'm using the latest 10.9.0 version of npm/npx...

brianlenz commented 1 month ago

I went ahead and filed a bug over here to see what they have to say: https://github.com/npm/cli/issues/7834

brianlenz commented 1 month ago

I'm going to close this, as I don't believe it's an issue with RN CLI.

Refer: https://github.com/npm/cli/issues/7834 https://github.com/npm/map-workspaces/pull/176