analytics-react-native: The package 'sovran-react-native' doesn't seem to be linked. Expo managed workflow

I’m running Expo managed workflow and running the app in Expo go which I know is not compatible with the package but I think I should still be able to run the app even though the analytics package is not going to work. Expected behaviour would be a warning and the package not working (like happens in the Sentry package f.ex.).

"expo": "^46.0.10",

Steps to reproduce

  • Create expo project (npx create-expo-app my-app)
  • Run yarn add @segment/analytics-react-native @segment/sovran-react-native @react-native-async-storage/async-storage
  • Add the following to your App.tsx so that the package gets used:
import { AnalyticsProvider, createClient } from '@segment/analytics-react-native';

const segmentClient = createClient({});

Snack https://snack.expo.dev/@danielgangverk/segment-snack?platform=ios

Expected behavior I would expect a warning that the package doesn’t work with Expo go instead of a crash

Actual behavior The app crashes in Expo go if @segment/analytics-react-native is imported anywhere

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 19 (5 by maintainers)

Most upvoted comments

@konoufo any idea when there will be a new release of sovran-react-native?

I see now that the ReadMe says

⚠️ @segment/analytics-react-native 2.0 is not compatible with Expo Go.

But I agree with @danielgangverk - it would be better if it was just completely disabled somehow when running in Expo Go and a warning displayed perhaps, instead of it blowing up.

Expo deprecated expo-analytics-segment in favor of this library from Expo 46 onwards, and it would be good to be able to continue using Expo Go after switching over to @segment/analytics-react-native.

@danielgangverk We have merged changes in both this library and sovran-react-native that should fix the issue. You can now use Expo Go without crashing. All you’ll get is a friendly warning. These changes should also be released soon. In the meantime, pulling from master should do the trick.

I have the same issue with ExpoGo and @segment/sovran-react-native, it crashes when running inside ExpoGo, I think a warning would be nice, it really doesn’t leave ExpoGo users with a lot of choices regarding Segment integration. I think it actually crashes right at the import and not even its usage.

@konoufo seems to be good now that I also updated sovran.

As a side question, do you happen to know how can I make this package work with react native web (or at least not crash in it)? Prior to using this I was using expo-segment (but they’re removing it in Expo SDK 46), hence now having to use this. expo-segment allowed me to use segment for react native web without crashing. Now, when I use this @segment/analytics-react-native and @segment/sovran-react-native instead of expo-segment for react native web build it crashes. I will investigate a solution, but was wondering if you had some guidance.

I setup two different analytics utilities using react-segments for the web and @segment/analytics-react-native for native

Hey @webjay . Do you see this as a warning ? If so, then yeah sounds like it’s working exactly as intended! Thanks for your feedback!

yes, I see it as a warning, but it still tracks. Thanks for the fix 😃

Hey @webjay . Do you see this as a warning ? If so, then yeah sounds like it’s working exactly as intended! Thanks for your feedback!

@konoufo wondering if while this is being fixed is it possible to use segmentio/analytics-next? what exactly does the react native library do that next doesn’t?

@konoufo do you know what version will this be fixed on? I notice 2.9.0 was just published and I tried that, but still crashing on my expo go. Not sure if the new version includes the fix.

UPDATE: nvm seems like sovran-react-native hasn’t been released yet. I will try when a new version is out.

Yeah that’s right; it’s going to be fully fixed in the next sovran-react-native release.

@danielgangverk @Jorundur A workaround for this (on iOS at least, have not tested Android yet) can be implemented by only requiring the module when we have the NativeModule, so it will work for any EAS build, with or without dev-client. For ExpoGo you could then just DEV log your Segment calls or skip them, that should keep ExpoGo usable at least.

    const { AnalyticsReactNative } = NativeModules;
    if (client || !AnalyticsReactNative) {
      return;
    }

    const segmentAnalytics = require('@segment/analytics-react-native');
    client = segmentAnalytics.createClient({
      writeKey,
    });`