Upload source maps for React Native
Contents
A minimum CLI version of 0.7.8 is required, but we recommend keeping up with the latest CLI version to ensure you have all of error tracking's features.
If you are using React Native Web, ensure source maps are generated
Then use our standard CLI approach to inject and upload them.
- 1
Download CLI
RequiredInstall
posthog-cli: - 2
Authenticate
RequiredTo authenticate the CLI, call the
logincommand. This opens your browser where you select your organization, project, and API scopes to grant: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_HOSTThe PostHog host to connect to [default: https://us.posthog.com] Project settings POSTHOG_CLI_PROJECT_IDPostHog project ID Project settings POSTHOG_CLI_API_KEYPersonal API key with error tracking writeandorganization readscopesAPI key settings You can also use the
--hostoption instead of thePOSTHOG_CLI_HOSTenvironment variable to target 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
RequiredAutomatic source map uploading is handled through the Gradle build process on Android and the Xcode build process on iOS.
EAS UpdatesIf you are using EAS Updates, source maps must be uploaded manually after running the update command. The automatic upload via Gradle/Xcode only runs during native builds, not during OTA updates.
TerminalThe
distfolder is the default output directory for EAS updates.- Expo: Update the app.json file in your app's root directory.
Expo Plugins that add modifications can only be used with prebuilding and managed EAS Build.
If you can use the
posthog-react-native/expoplugin, skip steps 2 and 3. If not, proceed with steps 2 and 3.Add the
posthog-react-native/expoplugin under theexpo.plugins.diffThe plugin accepts the following options:
Option Type Default Description disableSandboxingbooleantrueiOS only. When true, setsENABLE_USER_SCRIPT_SANDBOXING=NOon your main app target's Xcode build configurations duringexpo prebuild. This lets the source map upload script read.git/(for release metadata) and lets stock Expo projects build without manually declaring input/output files on every script phase.Example opting out of the sandbox change:
JSONWhen to opt outdisableSandboxing: falseis intended for organizations with compliance requirements that forbid disabling Xcode's user script sandbox. With the opt-out:- iOS source map uploads continue to work — errors still symbolicate
- Git metadata will not be attached to iOS releases (the UI chip shown for Android rows will be missing on iOS rows)
- Your project must already have every build-phase script (yours, Expo's, CocoaPods-generated) declaring its inputs and outputs, otherwise the build will fail
This setting only affects build-time scripts on the build machine. Your shipped app's runtime security is unchanged.
- 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.
diffIf you are not using the Expo plugin (step 1), you will need to also disable User Script Sandboxing for the upload script to work. In Xcode, go to Build Settings, search for User Script Sandboxing (
ENABLE_USER_SCRIPT_SANDBOXING) and set it to No. This is required because the script needs to read.git/for release metadata and executeposthog-cli, which are not allowed under Xcode's script sandbox.
Troubleshooting
Build fails with Sandbox: bash deny(1) file-read-data
You probably have { disableSandboxing: false } set in your plugin options, or your Xcode project has ENABLE_USER_SCRIPT_SANDBOXING = YES set explicitly somewhere that overrides the plugin. Stock Expo projects need the sandbox disabled because several build-phase scripts (Expo's expo-configure-project.sh, various CocoaPods-generated scripts) don't declare all their inputs. Either remove the opt-out, or declare inputs on every script phase and keep sandboxing on.