3

I am developing react native app and i am new in react-native, firstly I have worked for android platform and successfully build apk file. Now i want to run it for ios version with the command react-native run-ios from my mackbook but it's throws an error:

note: from starting i have developed this app on macbook

user-MacBook-Pro:myApp user$ react-native run-ios
error Cannot read property 'podfile' of null. Run CLI with --verbose flag for more details.
TypeError: Cannot read property 'podfile' of null
    at warnAboutPodInstall (/Users/user/project/myApp/node_modules/@react-native-community/cli-platform-ios/build/link/warnAboutPodInstall.js:43:90)
    at Object.runIOS [as func] (Users/user/project/myApp/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js:80:36)
    at Command.handleAction (Users/user/project/myApp/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:164:23)
    at Command.listener (Users/user/project/myApp/node_modules/commander/index.js:315:8)
    at Command.emit (events.js:198:13)
    at Command.parseArgs (Users/user/project/myApp/node_modules/commander/index.js:651:12)
    at Command.parse (Users/user/project/myApp/node_modules/commander/index.js:474:21)
    at setupAndRun (Users/user/project/myApp/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:237:24)
    at Object.run (Users/user/project/myApp/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:184:11)
    at Object.<anonymous> (/usr/local/lib/node_modules/react-native-cli/index.js:117:7)

Podfile

 platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

 target 'myApp' do
  # Pods for myApp
  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

  target 'myAppTests' do
    inherit! :search_paths
    # Pods for testing
  end

  use_native_modules!
end

target 'myApp-tvOS' do
  # Pods for myApp-tvOS

  target 'myApp-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

please help me who knows the solution. Thanks in advance.

Bellal Hossain
  • 240
  • 3
  • 8

3 Answers3

2
  1. Open Terminal
  2. Move ios folder under React-Native project
  3. Run pod install command - This will install all linked libraries for the installed rpm modules that require linking.
  4. After that run react-native run-ios or Double click on the projectName.xcworkspace, this will open the Xcode.
  5. Select device to run and play the project.
  • Thanks for your answer : when run the command pod install from ios directory this happens.. user-MacBook-Pro:ios user$ pod install [!] Invalid `Podfile` file: undefined method `[]' for nil:NilClass. # from /Users/user/project/myApp/ios/Podfile:42 # ------------------------------------------- # > use_native_modules! # end # ------------------------------------------- – Bellal Hossain Jan 27 '20 at 08:42
  • Please refer:- https://stackoverflow.com/questions/58423002/react-native-ios-invalid-podfile-file-undefined-method-for-nilnilcl & https://github.com/react-native-community/cli/issues/860 – Hussain Chhatriwala Jan 27 '20 at 11:53
1
  • First of all you need to know the basics of React Native. You can view official instructions of how to run React Native project on device from here

  • But before running application on iOS you need to do some additional things


  • Navigate into ios folder inside your root folder of project
  • Open terminal from active location and run this command

pod install

  • If you need to more about cocoapods visit this

  • After that open XCODE and navigate into ios folder and open your project file with the extension with .xcworkspace

MyProject.xcworkspace

  • Now you can run your iOS application via XCODE but before running application make sure you have clean your build folder ( Command+Shift+K ) and rebuild ( Command+B ) the project using XCODE.
  • Finally choose the device and run your application from XCODE. ( Command+R )
Akila Devinda
  • 5,054
  • 3
  • 19
  • 35
  • 1
    Thanks for your answer : when run the command pod install from ios directory this error occurs-> user-MacBook-Pro:ios user$ pod install [!] Invalid `Podfile` file: undefined method `[]' for nil:NilClass. # from /Users/user/project/myApp/ios/Podfile:42 # ------------------------------------------- # > use_native_modules! # end # ------------------------------------------- – Bellal Hossain Jan 27 '20 at 08:44
  • 1
    @BellalHossain see this issue -> https://github.com/react-native-community/cli/issues/860 – Akila Devinda Jan 27 '20 at 08:48
1

In a terminal, from your toplevel project directory run these commands:

cd ios # <-- To get into your ios subdirectory
ls

You should see a file named "Podfile" like shown here:

drwxr-xr-x   8 r  staff    256 Sep 21 14:04 AwesomeTSProject
-rw-r--r--   1 r  staff    749 Sep 21 14:04 Podfile

Next run the following command:

pod install

You should see files like these created:

drwxr-xr-x   4 r  staff    128 Sep 21 14:04 AwesomeTSProjectTests
drwxr-xr-x@  5 r  staff    160 Sep 21 14:22 AwesomeTSProject.xcworkspace
drwxr-xr-x  10 r  staff    320 Sep 29 10:00 .
drwxr-xr-x@  4 r  staff    128 Sep 29 10:19 AwesomeTSProject.xcodeproj
-rw-r--r--   1 r  staff  19077 Sep 29 10:19 Podfile.lock
-rw-r--r--@  1 r  staff   6148 Sep 30 04:00 .DS_Store
drwxr-xr-x  26 r  staff    832 Jan  9 09:01 Pods
drwxr-xr-x  25 r  staff    800 Jan  9 09:42 ..

As long as you don't see any errors, you can now run the following commands:

cd ..  

You should be popped up out of the ios folder and moved up to your parent project directory.

npx react-native run-ios

If all goes well, you should see an iOS simulator with your App.

yivi
  • 42,438
  • 18
  • 116
  • 138