|
| 1 | +--- |
| 2 | +title: Migrate from sentry-expo |
| 3 | +sidebar_order: 3 |
| 4 | +description: "Learn about migrating from sentry-expo to @sentry/react-native" |
| 5 | +--- |
| 6 | + |
| 7 | +<Alert level="info" title="Experimental Support"> |
| 8 | + |
| 9 | +Expo support is currently experimental and available since version `5.16.0-alpha.4`. |
| 10 | + |
| 11 | +Experimental support means it may have bugs. We recognize the irony. |
| 12 | + |
| 13 | +</Alert> |
| 14 | + |
| 15 | +This guide scribes how to migrate from `sentry-expo` to `@sentry/react-native` in your Expo application. |
| 16 | + |
| 17 | +## Remove `sentry-expo` |
| 18 | + |
| 19 | +First, remove `sentry-expo` from your dependencies: |
| 20 | + |
| 21 | +```bash {tabTitle:npm} |
| 22 | +npm uninstall sentry-expo |
| 23 | +``` |
| 24 | + |
| 25 | +```bash {tabTitle:Yarn} |
| 26 | +yarn remove sentry-expo |
| 27 | +``` |
| 28 | + |
| 29 | +### Install `@sentry/react-native` |
| 30 | + |
| 31 | +Install the `@sentry/react-native` package: |
| 32 | + |
| 33 | +```bash {tabTitle:Expo} |
| 34 | +npx expo install @sentry/react-native |
| 35 | +``` |
| 36 | + |
| 37 | +```bash {tabTitle:npm} |
| 38 | +npm install --save @sentry/react-native |
| 39 | +``` |
| 40 | + |
| 41 | +```bash {tabTitle:Yarn} |
| 42 | +yarn add @sentry/react-native |
| 43 | +``` |
| 44 | + |
| 45 | +### Fix Imports |
| 46 | + |
| 47 | +Replace all imports of `sentry-expo` with `@sentry/react-native`: |
| 48 | + |
| 49 | +```diff {tabTitle:JavaScript} |
| 50 | +- import * as Sentry from 'sentry-expo'; |
| 51 | ++ import * as Sentry from '@sentry/react-native'; |
| 52 | +``` |
| 53 | + |
| 54 | +Replace `sentry-expo` exports `Browser` and `React` with `@sentry/react`: |
| 55 | + |
| 56 | +```diff {tabTitle:JavaScript} |
| 57 | +- import { Browser, React } from 'sentry-expo'; |
| 58 | ++ import * as Browser from '@sentry/react'; |
| 59 | ++ import * as React from '@sentry/react'; |
| 60 | +``` |
| 61 | + |
| 62 | +Replace `sentry-expo` export `Native` with `@sentry/react-native`: |
| 63 | + |
| 64 | +```diff {tabTitle:JavaScript} |
| 65 | +- import { Native } from 'sentry-expo'; |
| 66 | ++ import * as Sentry from '@sentry/react-native'; |
| 67 | +``` |
| 68 | + |
| 69 | +### Review `Sentry.init` Options |
| 70 | + |
| 71 | +The `enableInExpoDevelopment` option is no longer supported. If you were using it, remove it and replace it with a `__DEV__` check, or leave the SDK enabled in development. |
| 72 | + |
| 73 | +```diff {tabTitle:JavaScript} |
| 74 | +Sentry.init({ |
| 75 | +- enableInExpoDevelopment: true, |
| 76 | ++ enabled: __DEV__, |
| 77 | +}); |
| 78 | +``` |
| 79 | + |
| 80 | +### Changes to Default Tags |
| 81 | + |
| 82 | +Expo-specific tags are no longer added by default. If you were using them, you can add them manually: |
| 83 | + |
| 84 | +```js |
| 85 | +import Constants from "expo-constants"; |
| 86 | +import * as Device from "expo-device"; |
| 87 | +import * as Updates from "expo-updates"; |
| 88 | + |
| 89 | +import * as Sentry from "@sentry/react-native"; |
| 90 | + |
| 91 | +Sentry.setExtras({ |
| 92 | + manifest, |
| 93 | + deviceYearClass: Device.deviceYearClass, |
| 94 | + linkingUri: Constants.linkingUri, |
| 95 | +}); |
| 96 | + |
| 97 | +Sentry.setTag("expoReleaseChannel", Updates.manifest.releaseChannel); |
| 98 | +Sentry.setTag("appVersion", Updates.manifest.version); |
| 99 | +Sentry.setTag("appPublishedTime", Updates.manifest.publishedTime); |
| 100 | +Sentry.setTag("expoSdkVersion", Updates.manifest.sdkVersion); |
| 101 | +Sentry.setTag("deviceId", Constants.sessionId); |
| 102 | +Sentry.setTag("appOwnership", Constants.appOwnership || "N/A"); |
| 103 | +if (Constants.appOwnership === "expo" && Constants.expoVersion) { |
| 104 | + setTag("expoAppVersion", Constants.expoVersion); |
| 105 | +} |
| 106 | +Sentry.setTag("expoChannel", Updates.channel); |
| 107 | +``` |
| 108 | + |
| 109 | +## Review `react-native-web` Compatibility |
| 110 | + |
| 111 | +The `sentry-expo` package automatically switched to `@sentry/react` for `react-native-web` builds. This is no longer the case with `@sentry/react-native` which supports `react-native-web` out of the box. |
| 112 | + |
| 113 | +Note that some features might not be supported or work differently in `@sentry/react-native` on `react-native-web` compared to direct usage of `@sentry/react`. Verify in your application that the features you use work as expected. |
| 114 | + |
| 115 | +To continue using `@sentry/react` for `react-native-web` builds, see [@sentry/react](/platforms/javascript/guides/react/) for more details about the web React package. |
| 116 | + |
| 117 | +## Set Up the `@sentry/react-native` Expo and Metro Plugins |
| 118 | + |
| 119 | +Next, [set up the Expo and Metro plugins](/platforms/react-native/manual-setup/expo/) for `@sentry/react-native`. |
0 commit comments