expo: [expo-branch] null is not an object (evaluating RNBranch.STANDARD_EVENT_ADD_TO_CART
🐛 Bug Report
Environment
This bug happens in Android
Expo CLI 3.0.9 environment info:
System:
OS: macOS 10.14.6
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.9.2 - ~/.nvm/versions/node/v10.16.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5522156
Xcode: 10.3/10G8 - /usr/bin/xcodebuild
npmPackages:
expo: ^34.0.1 => 34.0.4
react: 16.8.3 => 16.8.3
react-native: https://github.com/expo/react-native/archive/sdk-34.0.0.tar.gz => 0.59.8
npmGlobalPackages:
expo-cli: 3.0.9
Steps to Reproduce
import * as whatever from 'expo-branch'
OR
import whatever from 'expo-branch'
OR
import { Branch } from 'expo-branch'
npm start- Scan QR code on Expo on Android app
- See red screen of death:

Expected Behavior
It does not break.
Actual Behavior
It breaks.
Reproducible Demo
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 7
- Comments: 50 (20 by maintainers)
I’m stuck with the same problem.
I’m trying with SDK 35 and still getting that error on IOS and Android. The error happens importing as
and
I read about the Android support here, and followed this instructions.
error:
null is not an object (evaluating 'RNBranch.STANDARD_EVENT_ADD_TO_CART')i’m missing something?
Also, for those interested, I’ve ended up handling it this way:
and then
import Branch from 'my-branch'. The above code would obviously need to mock all functions called by your code.Just want some clarification on @sjchmiela reply.
So since there is no support with the Expo client, would that mean in order to test branch functionality (for iOS) we would have to do a standalone build and upload to Testflight?
Is there any other workflow for this at the moment? And is Expo client support for branch something in the works?
Thanks for your help.
Same here. We can´t test in in the iOS Simulator? SDK 35, get the same error in iOS: RNBranch.Standard_Event_Add_to_Card
Thanks for the reply, @sjchmiela! So is included in the build but can’t be tested first because the app crashes. What about IOS? Is also crashing in Expo client in SDK 35, but works on SDK 34. Seems to me that is the same as before and devs need to eject from expo to use it properly. Or there is a way to integrate it without breaking the app?
Please, correct me if I’m wrong. Thanks
EDIT: Well, @AryanJ-NYC suggestion will work without broking the app. That point is covered.
To import dynamically using
await, what worked for us was:Yes, it has, @sjchmiela.
This would mean that, while
import { DangerZone } from 'expo'was a safe import,import ... from 'expo-branch' // or react-native-branchis unsafe sinceRNBranchisnullin Expo client. This lead me to use the following pattern:which now does not return the same error as above. Unfortunately, I’m still unsuccessfully able to run a built app. Will keep updated.
@yodaheis Just be aware that
import()returns aPromise. You should probably make it something like…@davidbiller I don’t know why, but it works now. I import it with regular top import and I left the
if (Constants.appOwnership === 'standalone') {.Thank you! I spent about 5 hours on this.
That’s right, that should do the work! To inspect whether
expo-branchhas been added to the build, expand theresolve native modulesstep inexpo.io/buildsand verify whetherAdding expo-branch:1.0.0is present there. If it is, most probably all the required native modules have been added to the application.This hasn’t been communicated clearly anywhere, since we haven’t announced this feature publicly yet, but when trying to use Branch you will need to remember that:
RNBranch, i. e. native module, isnullin Expo client.expo-branchis a wrapper aroundreact-native-branchwhich allows us to optionally include it in standalone applications depending ondependenciesfield inpackage.json. Branch will be available in your application only in Expo-built apps (expo build:android) and only if you addexpo-branchto your NPM dependencies.expo-branchincluded and importing fromexpo-branchdoesn’t work due to some problem with exports, try importing fromreact-native-branch, as @cruzach proposed here.expo-branch/react-native-branchthere. 🙂Has this description helped understand current situation? 😅
This works on iOS but still results in the same screen (shown in OP) on Android.
I’ve updated https://github.com/AryanJ-NYC/expo-sandbox to reflect the changes you suggest.