Sentry-react-native: 'RCTEventEmitter.h' file not found while building iOS swift based | React Pod deprecated

Created on 1 Feb 2018  ·  23Comments  ·  Source: getsentry/sentry-react-native

OS:

  • [ ] Windows
  • [x] MacOS
  • [ ] Linux

_Platform:_

  • [x] iOS
  • [ ] Android

Output of node -v && npm -v && npm ls --prod --depth=0

v8.9.0
5.5.1

├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]

Config:

Sentry.config('https://[email protected]/...', {
....
}).install()

I have following issue:

I'm trying to setup sentry in my react-native project without success.

I've already put up an issue in sentry-wizard regarding users that use swift instead of objC because the setup is not done properly when using swift.

But basically, after linking everything and manually add the excerpt of code to AppDelegate.swift I do pod install to get the Sentry libs, but apparently React Pod also comes as a dependency, despite being deprecated. I'm not sure if that's causing the issue, but after all these steps, while build the project I always get 'RCTEventEmitter.h' file not found in RNSentryEventEmitter.h even though I can navigate to the RCTEventEmitter interface file.

Any help would be appreciated.
Thanks in advance.

Steps to reproduce:

  • React Native project using swift for iOS
  • yarn add react-native-sentry
  • react-native link react-native-sentry
  • pod install
  • Manually add missing code to AppDelegate.swift
  • Build Project

Actual result:
image

Expected result:

  • Successful build

Most helpful comment

Got it working!

For anyone reading this, these are the steps I took:

  1. Do NOT use CocoaPods for react-native-sentry
  2. Follow the standard install steps:
    a) yarn react-native-sentry
    b) react-native link react-native-sentry
  3. If your Podfile was modified by the setup script, remove any reference of ReactNativeSentry
  4. Open Xcode and drag node_modules/react-native-sentry/ios/RNSentry.xcodeproj into your project's Libraries directory
  5. Open your project's "Linked Frameworks and Libraries" and add libRNSentry.a

Hope that helps!

All 23 comments

I can confirm that I'm having this exact same issue. And I'm not using Swift, so I'm pretty sure it has nothing to do with that.

Not sure if downgrading will help - but gonna give it a shot

EDIT: Downgrading to 0.32.1 did not help

Got it working!

For anyone reading this, these are the steps I took:

  1. Do NOT use CocoaPods for react-native-sentry
  2. Follow the standard install steps:
    a) yarn react-native-sentry
    b) react-native link react-native-sentry
  3. If your Podfile was modified by the setup script, remove any reference of ReactNativeSentry
  4. Open Xcode and drag node_modules/react-native-sentry/ios/RNSentry.xcodeproj into your project's Libraries directory
  5. Open your project's "Linked Frameworks and Libraries" and add libRNSentry.a

Hope that helps!

Hey @amsul thanks for the reply! I'll give it a shot and see it it works!
EDIT: I can't seem to add the needed code to my AppDelegate.swift because it never finds the RNSEntry module..

@Jflima92 since you're using Swift, you likely have to add the import to your bridging header first.

@amsul I've done that after adding the react-native-sentry ios folder to the headers search path with recursive mode, but still no luck. Am I missing something? 😞

EDIT: I was unnecessarily importing RNSentry in .swift, there's no need to import, now it works!!

@amsul Thanks so much for your post. Was struggling to get Sentry installed and built without errors and NOT using CocoaPods was the way to go.

So am I correct to conclude that the official install instructions for react native on iOS are wrong?

Just trying to understand if this is a workaround for some rare issue, or if the documentation is outdated.

@askielboe not sure if it's "wrong" per se..I've seen other RN packages suggest similar steps of adding a dependency to the Podfile that points to node_modules. But I've never been able to get my builds to fully work in those cases.

However, this setup seems to always work.

Yep, that's also my experience. Even for packages that very explicitly demands that I use cocoapods, I can never get it to work properly. But manually linking, as in this case, always seems to work.

Guess I was just wondering what the reason was to add the podspec when it seems not to work in a lot of cases. I like cocoapods for native development, and it would indeed be nice if it worked for RN native dependencies as well.

@amsul this is the only thing that finally fixed this header files issue both locally and on our CI. thank you!

For me, this commit was the cause of the error: https://github.com/getsentry/react-native-sentry/commit/320651c23144664fb193c34a484a9fbee492dee9#diff-d8cd0abcb714ce13da6a6f2645e214af

After reverting that, the build finishes without problems. As a workaround until it's fixed or explained, I've added an npm post install script that reverts the commit.

if [ -f ./node_modules/react-native-sentry/SentryReactNative.podspec ]
then
  if ! grep "s.dependency 'React'" ./node_modules/react-native-sentry/SentryReactNative.podspec
  then
      sed -i.bak \
         $'s#s.dependency \'Sentry\'#s.dependency \'React\'\\\n  s.dependency \'Sentry\'#g' \
         ./node_modules/react-native-sentry/SentryReactNative.podspec
  fi
fi

(no sed-expert, but it seems to work...)

@othorin Do you still have to error when using CocoaPods 1.4.0 as described here: https://github.com/getsentry/react-native-sentry/issues/395#issuecomment-388215879

TBH I don't really had time to wrap my head around this issue if the error lies on the CocoaPods or react-native side.
Both seem to have downsides but people seem to have more trouble now than before, I've asked the contributor to elaborate more on this, otherwise I will revert this back so React is in the podspec.

Hey, so I reverted the change, React is back in the podspec.
Version 0.37.0 is on its way, sorry for the inconvenience this has caused.

Same issue
react-native-sentry: ^0.37.1,
react-native: 0.51.0

i try all way above, it's still error =))))

@amsul You saved my life :D

@amsul's answer should be in Sentry's documentation.

@amsul you're the best!

good solution

@amsul Thanks, this works. Btw, the lib that we should add is libRNSentry.a

As a quick side note, I tried it on fresh clean swift ios project.
Followed the react-native docs for integrating in an existing app here: https://facebook.github.io/react-native/docs/integration-with-existing-apps

And did:

yarn add react-native-sentry
react-native link react-native-sentry
cd ios
pod install

everything worked without doing any manual linking.

For my part, the steps given by @amsul worked, thanks a lot!

But I ultimately also figured out how to link Sentry with react-native link. The problem came from the fact that I did not have all of React Native's required podspecs. Sentry was then adding a wrong version of React (which even issued a deprecation warning on pod install).
Adding the podspecs according to the React Native install guide, and then $ react-native link, $ cd ios/; pod install worked:

  ...

  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'CxxBridge', # Include this for RN >= 0.47
    'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
    'RCTText',
    'RCTNetwork',
    'RCTWebSocket', # needed for debugging
    # Add any other subspecs you want to use in your project
  ]
  # Explicitly include Yoga if you are using RN >= 0.42.0
  pod "yoga", :path => "../node_modules/react-native/ReactCommon/yoga"

  # Third party deps podspec link
  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'

  ...

EDIT: You also need to remove all references to React and its dependencies in Xcode > YourProject > Libraries. If React Native is included directly (as it is when using react-init), then having it in your Pods will include it twice and all kinds of weird problems start happening (the devMenu stopped opening on shake in my case, among other things).

@silvainSayduck that approach would work as well.

However, my concern with doing that is that it requires quite a bit of maintenance and knowledge of RN's dependencies to keep it working. Especially through upgrades as dependencies are changed/added/removed. It's a nightmare to debug that at times.

You can see hints of that in the snippet you posted as well, which requires separate dependencies for 0.42 0.43, 0.47, for debugging etc. This is going to be a never ending thing to maintain.

Was this page helpful?
0 / 5 - 0 ratings