Upload source maps for React Native
- 1
Download CLI
RequiredInstall
posthog-cli: - 2
Authenticate
RequiredTo authenticate the CLI, you can call the
logincommand and follow the instructions:TerminalIf you are using the CLI in a CI/CD environment such as GitHub Actions, you can set environment variables to authenticate:
Environment Variable Description Source POSTHOG_CLI_ENV_IDPostHog project ID Environment settings POSTHOG_CLI_TOKENPersonal API key with error tracking writeandorganization readscopesAPI key settings Use the
--hostoption in subsequent commands to specify a different PostHog instance / or region. For EU users:Terminal - 3
Inject
RequiredExpo 50 or laterAutomatic source map injection works only in React Native apps using Expo 50 or later, as it relies on Expo’s built-in debug ID injection.
Create or update the metro.config.js file in your app's root directory so that it looks like this:
diff - 4
Upload
RequiredNo automatic source map uploads on React Native webAutomatic source map uploading is handled through the Gradle build process on Android and the Xcode build process on iOS. For React Native web, please use our CLI instead.
- Android: Update the
/android/app/build.gradlefile from your app's root directory so that it looks like this:
diff- iOS: Update the
/ios/$yourProjectName.xcodeproj/project.pbxprojfile (replace$yourProjectNamewith your project's actual name). You need to locate theBundle React Native code and imagesbuild step.
To do this through Xcode, open your project in Xcode, go to the project settings, navigate to Build Phases, select Bundle React Native code and images, and apply the changes shown below.
diff- Web: Ensure that your React Native web build generates source maps.
Terminal - Android: Update the