Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[!] 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);} #45912

Open
mendozammatias opened this issue Aug 6, 2024 · 3 comments

Comments

@mendozammatias
Copy link

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.

# 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

console.log(require('@react-native-community/cli').bin)

with

console.log(require('../react-native/node_modules/@react-native-community/cli').bin)

produces this value for cli_bin:

/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
  1. run npm install inside react-native folder
  2. cd ios-app && pod init.
  3. Set Podfile as described on Description.
  4. run pod install inside ios-app folder.

React Native Version

0.74.4

Affected Platforms

Runtime - iOS

Output of npx react-native info

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

[!] 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

@react-native-bot
Copy link
Collaborator

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.74.5. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot
Copy link
Collaborator

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@okwasniewski
Copy link
Contributor

I've checked this issue and unfortunately, I think it's not possible with the current implementation of the CLI.

If you take a look at this line in React Native CLI, it's trying to resolve the path without taking into account that the react-native directory can be in a different place:
https://github.com/react-native-community/cli/blob/6a61d5dcc99c6430b74c1095e05ffb315909b078/packages/cli-platform-ios/native_modules.rb#L25

Probably this is something that can be adjusted. WDYT @thymikee @szymonrybczak @TMisiukiewicz?

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

No branches or pull requests

3 participants