Repository: react-native
Issue: [!] Invalid `Podfile` file: [!] route/to/node -e try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}
Labels: Needs: Triage :mag:,Newer Patch Available

### Description

I'm trying to integrate React Native with an existing iOS app but since it's a big running application, I need to have the React Native codebase separated so the iOS project cannot be a subfolder of the React Native application.

When running `pod install`, this error appears: 
```
[!] Invalid `Podfile` file: [!] route/to/node -e try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}
```

This is how it looks like my Podfile.

``` rb
# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "../react-native/node_modules/react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'ios-app' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/../react-native"
  )

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
      # :ccache_enabled => true
    )
  end
end
```


While debugging, I've found the issue is in this file: 
`react-native/node_modules/@react-native-community/cli-platform-ios/native_modules.rb`. 

The value from `cli_resolve_script` cannot resolve the correct route.

Replacing the line 
```js 
console.log(require('@react-native-community/cli').bin)
``` 
with 
```js 
console.log(require('../react-native/node_modules/@react-native-community/cli').bin)
``` 
produces this value for `cli_bin`: 
``` js
/route-to-app/react-native/node_modules/@react-native-community/cli/build/bin.jserror:
```

Is it possible to run iOS not as a subfolder of the React Native project or am I missing something?

### Steps to reproduce

1. Create a project with this structure:
```
root
├── ios-app : iOS Swift Project created from scratch with XCode.
│   └──  ...all other iOS files
└── react-native
    ├── index.js
    ├── metro.config.js
    ├── package-lock.json
    └── package.json
```
3. run `npm install` inside `react-native` folder
4. `cd ios-app && pod init`.
5. Set Podfile as described on Description.
6. run `pod install` inside `ios-app` folder.

### React Native Version

0.74.4

### Affected Platforms

Runtime - iOS

### Output of `npx react-native info`

```text
System:
  OS: macOS 14.5
  CPU: (10) arm64 Apple M1 Pro
  Memory: 351.69 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.15.1
    path: ~/.nvm/versions/node/v20.15.1/bin/node
  Yarn: Not Found
  npm:
    version: 10.7.0
    path: ~/.nvm/versions/node/v20.15.1/bin/npm
  Watchman:
    version: 2024.07.15.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2411.12071903
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.12
    path: /Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/javac
  Ruby:
    version: 3.3.4
    path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
```


### Stacktrace or Logs

```text
[!] Invalid `Podfile` file: [!] route/to/node -e try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}
```


### Reproducer

https://github.com/mendozammatias/ios-brownfield

### Screenshots and Videos

_No response_