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

Integration to existing Apps: require_relative not working as expected. Only works if the App is inside the React Native root ios directory #33941

Closed
sedhha opened this issue Jun 1, 2022 · 4 comments
Labels
Platform: iOS iOS applications. Resolution: For Stack Overflow A question for Stack Overflow. Applying this label will cause issue to be closed. Tool: CocoaPods

Comments

@sedhha
Copy link

sedhha commented Jun 1, 2022

Description

I am trying to use require_relative, but it seems like it only works when the folder structure is like this:

- src
---- ios
-------- podFile
---- node_modules

and try to do pod install with podFile as:

# Dev Changes
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

this succeeds installation, however, if I update the structure like this:

- src
---- ios
-------- node_modules
-------- podFile

and try to do pod install with podFile as:

require_relative './node_modules/react-native/scripts/react_native_pods'
require_relative './node_modules/@react-native-community/cli-platform-ios/native_modules'

this fails with the following error:

Analyzing dependencies
Fetching podspec for DoubleConversion from ../../reactNativeApp/content//node_modules/react-native/third-party-podspecs/DoubleConversion.podspec
Fetching podspec for RCT-Folly from ../../reactNativeApp/content//node_modules/react-native/third-party-podspecs/Folly.podspec
/usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/user_interface/error_report.rb:34:in force_encoding': can't modify frozen String (FrozenError) from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/user_interface/error_report.rb:34:in report'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:66:in report_error' from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:396:in handle_exception'
from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:337:in rescue in run' from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:324:in run'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:52:in run' from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/bin/pod:55:in <top (required)>'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/bin/pod:23:in load' from /usr/local/Cellar/cocoapods/1.11.3/libexec/bin/pod:23:in

'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/uri/generic.rb:1490:in find_proxy': relative URI: /reactNativeApp/content/node_modules/react-native/third-party-podspecs/Folly.podspec (URI::BadURIError) from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:209:in block in open_loop'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:226:in block in open_loop' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:224:in catch'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:224:in open_loop' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:165:in open_uri'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/external_sources/podspec_source.rb:19:in blo ssahil1@LAMU02D86CPMD6R native_ios_app % pod install Analyzing dependencies Fetching podspec for DoubleConversionfrom../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec/usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/user_interface/error_report.rb:34:inforce_encoding': can't modify frozen String (FrozenError)
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/user_interface/error_report.rb:34:in report' from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:66:in report_error'
from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:396:in handle_exception' from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:337:in rescue in run'
from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:324:in run' from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:52:in run'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/bin/pod:55:in <top (required)>' from /usr/local/Cellar/cocoapods/1.11.3/libexec/bin/pod:23:in load'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/bin/pod:23:in <main>' /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/uri/generic.rb:1490:in find_proxy': relative URI: /reactNativeApp/content/node_modules/react-native/third-party-podspecs/DoubleConversion.podspec (URI::BadURIError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:209:in block in open_loop' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:226:in block in open_loop'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:224:in catch' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:224:in open_loop'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:165:in open_uri' from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/external_sources/podspec_source.rb:19:in blo
ssahil1@LAMU02D86CPMD6R native_ios_app % pod install
Analyzing dependencies
Fetching podspec for DoubleConversion from ../../reactNativeApp/content/node_modules/react-native/third-party-podspecs/DoubleConversion.podspec
Fetching podspec for Folly from ../../reactNativeApp/content/node_modules/react-native/third-party-podspecs/Folly.podspec
/usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/user_interface/error_report.rb:34:in force_encoding': can't modify frozen String (FrozenError) from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/user_interface/error_report.rb:34:in report'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:66:in report_error' from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:396:in handle_exception'
from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:337:in rescue in run' from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:324:in run'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:52:in run' from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/bin/pod:55:in <top (required)>'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/bin/pod:23:in load' from /usr/local/Cellar/cocoapods/1.11.3/libexec/bin/pod:23:in '
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/uri/generic.rb:1490:in find_proxy': relative URI: /reactNativeApp/content/node_modules/react-native/third-party-podspecs/Folly.podspec (URI::BadURIError) from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:209:in block in open_loop'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:226:in block in open_loop' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:224:in catch'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:224:in open_loop' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/open-uri.rb:165:in open_uri'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/external_sources/podspec_source.rb:19:in block in fetch' from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:86:in titled_section'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/external_sources/podspec_source.rb:11:in fetch' from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/installer/analyzer.rb:993:in fetch_external_source'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/installer/analyzer.rb:972:in block (2 levels) in fetch_external_sources' from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/installer/analyzer.rb:971:in each'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/installer/analyzer.rb:971:in block in fetch_external_sources' from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:64:in section'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/installer/analyzer.rb:970:in fetch_external_sources' from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/installer/analyzer.rb:117:in analyze'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:416:in analyze' from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:241:in block in resolve_dependencies'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:64:in section' from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:240:in resolve_dependencies'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:161:in install!' from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/command/install.rb:52:in run'
from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:334:in run' from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:52:in run'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/gems/cocoapods-1.11.3/bin/pod:55:in <top (required)>' from /usr/local/Cellar/cocoapods/1.11.3/libexec/bin/pod:23:in load'
from /usr/local/Cellar/cocoapods/1.11.3/libexec/bin/pod:23:in `'

I have two things to question:

  • What's causing this unexpected behaviour? Because when I keep the same node_modules folder next to ios it works fine which is kind of wierd.
  • Let's say my two folders ios and the node_modules sit into two different directories: https://github.com/sedhha/<IOS> and https://github.com/sedhha/<node_modules>. In that case, I can't use require_relative is there a better way to fetch them globally, something like require_absolute: git: https://<address_to_git_repo>.

Version

0.68.2

Output of npx react-native info

System:
OS: macOS 12.3.1
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 6.64 GB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.2.0 - /usr/local/bin/node
Yarn: 1.22.19 - ~/.yarn/bin/yarn
npm: 8.6.0 - /usr/local/bin/npm
Watchman: 2022.05.16.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK: Not Found
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.6010548
Xcode: 13.3.1/13E500a - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_312 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.68.2 => 0.68.2
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

  1. Create an ios project
  2. Place a node_modules folder inside ios project
  3. try to do require_relative and you will see the above error when doing pod install.

Snack, code example, screenshot, or link to a repository

CASE 1: podFile when installation succeeds:

# Dev Changes
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

CASE 2: podFiles when installation fails:

# Dev Changes
require_relative '../project/node_modules/react-native/scripts/react_native_pods'
require_relative '../project/node_modules/@react-native-community/cli-platform-ios/native_modules'

CASE 3: podFiles whne installation fails:

# Dev Changes
require_relative './node_modules/react-native/scripts/react_native_pods'
require_relative './node_modules/@react-native-community/cli-platform-ios/native_modules'
@react-native-bot react-native-bot added the Platform: iOS iOS applications. label Jun 1, 2022
@sedhha
Copy link
Author

sedhha commented Jun 1, 2022

After diving into the source code, I realized that if you don't supply the path in use_react_native by default it goes to ../nod_modules/react-native, so I updated my use_react_native to use_react_native!(:path => './Content/node_modules/react-native') which got me installation successful, however the other question still remains that I want to install this from remote git repo and not by adding the files in a folder within my repo. I have created a SO post around the same, can someone help me to achieve that? Here's the link: https://stackoverflow.com/questions/72456941/remotely-install-react-native-pods-ios-podfile-instead-of-require-relative

I am keeping the thread open for knowing the second thing I asked in my question, however the issue has been resolved, if moderators feel I should open a new thread, feel free to close this, otherwise I would close this once I get answer to my second question.

@dmytrorykun
Copy link
Contributor

Hello @sedhha, please refer to RN-Tester: https://github.com/facebook/react-native/tree/main/packages/rn-tester
It has flat directory structure.
As for your 2nd question: node_modules must be physically present locally on your machine, so require_relative must work if the relative path is correct.

@dmytrorykun dmytrorykun added Resolution: For Stack Overflow A question for Stack Overflow. Applying this label will cause issue to be closed. Tool: CocoaPods and removed Needs: Triage 🔍 labels Jun 20, 2022
@github-actions
Copy link

We are using GitHub issues exclusively to track bugs in the core React Native library. Please try asking over on Stack Overflow as it is better suited for this type of question.

@krmao
Copy link

krmao commented Aug 3, 2022

can you update https://reactnative.dev/docs/integration-with-existing-apps @dmitryrykun

RNTester is really much different with the doc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: iOS iOS applications. Resolution: For Stack Overflow A question for Stack Overflow. Applying this label will cause issue to be closed. Tool: CocoaPods
Projects
None yet
Development

No branches or pull requests

4 participants