react-native: Can't run react native app from existing ios app

I tried to run my react native app using RCTRootView but keep throwing this error

2019-09-27 16:28:42.163 [info][tid:com.facebook.react.JavaScript] 'Failed to print error: ', 'Requiring module "node_modules/react-native/Libraries/Utilities/Platform.ios.js", which threw an exception: Invariant Violation: TurboModuleRegistry.getEnforcing(...): \'PlatformConstants\' could not be found. Verify that a module by this name is registered in the native binary.'
2019-09-27 16:28:42.171 [fatal][tid:main] Unhandled JS Exception: TurboModuleRegistry.getEnforcing(...): 'PlatformConstants' could not be found. Verify that a module by this name is registered in the native binary.

React Native version:

React 16.9.0 React-Native 0.61.1

pod config

pod 'React', :path => 'react/node_modules/react-native/'
  pod 'React-Core', :path => 'react/node_modules/react-native/'
  # pod 'React-DevSupport', :path => 'react/node_modules/react-native/React'
  # pod 'React-fishhook', :path => 'react/node_modules/react-native/Libraries/fishhook'
  pod 'React-RCTActionSheet', :path => 'react/node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => 'react/node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => 'react/node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => 'react/node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => 'react/node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => 'react/node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => 'react/node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => 'react/node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => 'react/node_modules/react-native/Libraries/Vibration'
  # pod 'React-RCTWebSocket', :path => 'react/node_modules/react-native/Libraries/WebSocket'
  
  pod 'React-cxxreact', :path => 'react/node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => 'react/node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => 'react/node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => 'react/node_modules/react-native/ReactCommon/jsinspector'
  pod 'Yoga', :path => 'react/node_modules/react-native/ReactCommon/yoga'
  
  pod 'DoubleConversion', :podspec => 'react/node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => 'react/node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => 'react/node_modules/react-native/third-party-podspecs/Folly.podspec'

Steps To Reproduce

  1. create react app
  2. configure xcode follow pod file
  3. http://$host:$port/index.bundle?platform=ios

Describe what you expected to happen:

run seemlessly

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

Running Code in XCode

NSURL *jsCodeLocation = [NSURL URLWithString:@"http://192.168.1.67:19000/index.bundle?platform=ios"];
    _rctBridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation moduleProvider:nil launchOptions:nil];
    _rootView = [[RCTRootView alloc] initWithBridge:_rctBridge moduleName:@"AppHome" initialProperties:@{@"appId":self.marketApp.appId}];

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 12
  • Comments: 32

Most upvoted comments

I was able to fix this problem by adding the following podspecs:

  • React-CoreModules
  • ReactCommon/turbomodule/core
  • FBLazyVector
  • FBReactNativeSpec
  • RCTRequired
  • RCTTypeSafety

I used this commit for guidance.

Getting same error and tried all above solution, but can’t success…

Simulator Screen Shot - iPhone X - 2019-10-11 at 17 56 25

I’m using RN 0.61.2 with an existing iOS project.

Getting the same error as OP on v0.61.2, when adding RN to an existing iOS project following the guide: https://facebook.github.io/react-native/docs/integration-with-existing-apps

The Podfile required quite a few changes compared to the Podfile in the tutorial, I think the tutorial might be outdated. After getting around that problem, getting the same error OP mentioned:

[fatal][tid:main] Unhandled JS Exception: TurboModuleRegistry.getEnforcing(...): 'PlatformConstants' could not be found. Verify that a module by this name is registered in the native binary.

I was on 0.60.5 then went to 0.61.1. Then I ran into this issue and downgraded back to 0.60.6 and now it is working for me.

I solved all of my problems by doing the following (dirty way but only one who worked after hours of trying):

$ react-native init tmpapp
$ cp tmpapp/ios/Podfile myapp/ios/
$ rm myapp/ios/Podfile.lock
$ cd myapp/ios/ ; pod install ; cd .. # EDIT: not sure if this is needed
$ react-native run-ios

Hope this helps anyone.

Following @BrianBatchelder comment, however I’m getting an issue with FBLazyVector and RCTRequired stating that

AccessibilityPrimitives.h file not found

This is how my Podfile looks like:

...
# React Native pods
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-Core/RCTWebSocket', :path => '../../node_modules/react-native/'

#pod 'ReactCommon/jscallinvoker', :path => "../../node_modules/react-native/ReactCommon"
#pod 'ReactCommon/turbomodule/core', :path => "../../node_modules/react-native/ReactCommon"
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 'Yoga', :path => '../../node_modules/react-native/ReactCommon/yoga'

#pod 'React-CoreModules', :podspec => '../../node_modules/react-native/React/CoreModules/React-CoreModules.podspec'
pod 'ReactCommon', :path => '../../node_modules/react-native/ReactCommon'
pod 'FBLazyVector', :podspec => '../../node_modules/react-native/Libraries/FBLazyVector/FBLazyVector.podspec'
pod 'FBReactNativeSpec', :podspec => '../../node_modules/react-native/Libraries/FBReactNativeSpec/FBReactNativeSpec.podspec'
pod 'RCTRequired', :podspec => '../../node_modules/react-native/Libraries/RCTRequired/RCTRequired.podspec'
pod 'RCTTypeSafety', :podspec => '../../node_modules/react-native/Libraries/TypeSafety/RCTTypeSafety.podspec'
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'
...

I’m using RN 0.61.2 with an existing iOS project.

@AustP downgraded too and working too here 👍

@qyhongfan I followed https://react-native-community.github.io/upgrade-helper/?from=0.59.10&to=0.61.2, I’m currently at my 5th try. So this is definitely not gonna help anyone here as this issue could come from react-native itself as much as a dependency. The thing is, compilation errors do not give enough informations for us to precisely know which dependancy could be causing the error, and we can’t afford spending a week testing them out one by one.

@BrianBatchelder I already added those podspecs in my Podfile but still ran into this issue. Did I miss something? I used upgrade-helper(https://react-native-community.github.io/upgrade-helper/?from=0.60.5&to=0.61.1) for guidance.

Finally after hours of struggle I was able to get it working, I manually run react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios' and add the /assets folder in XCode. If you don’t have a /Resources folder create one, the main.jsbundle will appear there after you run the script. If it doesn’t appear, manually do add files... with XCode and add it. Then do Archive from XCode for generic device. Note: if you aren’t using index.js as your main js file rename it in the script above.

This way I was able to get it working for release. @ahartzog

I solved my problems by updating from 0.59.10 to 0.60.4 and then to 0.61.2. Now my issue is that just like in 0.60, fetch returns a blob everytime…

@BrianBatchelder currently working on this same issue. I’ve included all of those podspecs. Did you end up fixing it for RN 0.61, 0.61.1 or another version?