Upload source maps for React Native

CLI version requirement

The Xcode and Gradle upload scripts in posthog-react-native 4.90.0 and later upload with hog, PostHog's CLI. When hog isn't installed, they upload with posthog-cli and warn that posthog-cli is deprecated. Earlier versions of the scripts only run posthog-cli, version 0.7.8 or later. Native symbol uploads move to hog with the native SDKs' tooling, as native crash symbolication explains.

React Native Web

If you are using React Native Web, ensure source maps are generated

Terminal
# example command
# Files are usually under the '$buildFolder/_expo/static/js/web' folder ($name.js and $name.js.map)
npx expo export --source-maps --platform web

Then use our standard CLI approach to inject and upload them.

  1. Install hog

    Required

    Install hog, PostHog's CLI:

    curl -fsSL https://posthog.com/install.sh | sh

    In GitHub Actions, install hog with the PostHog/setup-hog action:

    YAML
    - uses: PostHog/setup-hog@v1

  2. Authenticate

    Required

    Log in to PostHog. This opens your browser, where you approve the login:

    Terminal
    hog auth login

    If posthog-cli is already logged in on this machine, import that login instead:

    Terminal
    hog auth migrate

    hog reads only the HOG_* names. The PostHog build plugins and upload scripts still pass the old POSTHOG_CLI_* names to hog for now, with a warning for each one. A hog command you run yourself needs the HOG_* names. The migration guide lists each rename.

  3. Inject

    Required
    Expo 50 or later

    Automatic 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
    -const { getDefaultConfig } = require("expo/metro-config");
    +const { getPostHogExpoConfig } = require('posthog-react-native/metro')
    -const config = getDefaultConfig(__dirname);
    +const config = getPostHogExpoConfig(__dirname)
    module.exports = config
  4. Upload

    Required

    Automatic source map uploading is handled through the Gradle build process on Android and the Xcode build process on iOS.

    EAS Updates

    If 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.

    Terminal
    # After running `eas update` or `npx expo export --dump-sourcemap`, upload source maps from the output directory
    hog error-tracking upload dist --kind hermes

    The dist folder is the default output directory for EAS updates.

    1. 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/expo plugin, skip steps 2 and 3. If not, proceed with steps 2 and 3.

    Add the posthog-react-native/expo plugin under the expo.plugins.

    diff
    {
    "expo": {
    ...
    "plugins": [
    ...
    + "posthog-react-native/expo"
    ]
    }
    }

    If your project has a checked-in ios/ directory, run or rerun the iOS prebuild after adding or upgrading the plugin:

    Terminal
    npx expo prebuild --platform ios

    This reapplies the config plugin to the existing Bundle React Native code and images build phase. When upgrading from posthog-react-native 4.61.0 or earlier to a newer version, the plugin automatically migrates the previously generated PostHog command. You do not need to edit project.pbxproj manually.

    The plugin accepts the following options:

    OptionTypeDefaultDescription
    disableSandboxingbooleantrueiOS only. When true, sets ENABLE_USER_SCRIPT_SANDBOXING=NO on your main app target's Xcode build configurations during expo 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.
    skipOnConflictbooleanfalseAdds --skip-on-conflict to JavaScript source map uploads on iOS and Android. Use this when the same build can upload the same source maps more than once and you want duplicate uploads to be skipped instead of failing. Requires posthog-react-native 4.49.1 or later. When uploadNativeSymbols is enabled, it also applies to native iOS dSYM uploads: a build whose dSYM already exists in PostHog with different content skips the upload and keeps the existing symbols instead of failing. The dSYM behavior requires posthog-react-native 4.56.1 or later, posthog-ios 3.64.7 or later, and posthog-cli 0.7.12 or later.
    dotenvFilestring–Path to a dotenv file containing your CLI credentials (API key, project ID, optional host), relative to the project root or absolute. During expo prebuild the path is wired into every upload hook: as the POSTHOG_CLI_DOTENV_FILE Xcode build setting on iOS, plus HOG_DOTENV_FILE from posthog-react-native 4.90.0, and as a posthog.dotenvFile entry in android/gradle.properties on Android. The JavaScript source map, dSYM, and ProGuard/R8 mapping uploads all read credentials from the file regardless of how the native build is started. Real environment variables take precedence and a missing file only logs a warning, so the same config works unchanged in CI. Requires posthog-react-native 4.60.0 or later. Uploads with posthog-cli also need posthog-cli 0.8.4 or later (older versions ignore the variable).

    Example opting out of the sandbox change:

    JSON
    {
    "expo": {
    "plugins": [
    ["posthog-react-native/expo", { "disableSandboxing": false }]
    ]
    }
    }
    When to opt out

    disableSandboxing: false is 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, so 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.

    Example skipping duplicate JavaScript source map uploads:

    JSON
    {
    "expo": {
    "plugins": [
    ["posthog-react-native/expo", { "skipOnConflict": true }]
    ]
    }
    }

    Example reading CLI credentials from a gitignored .env file at build time:

    JSON
    {
    "expo": {
    "plugins": [
    ["posthog-react-native/expo", { "dotenvFile": ".env" }]
    ]
    }
    }
    .env
    HOG_PERSONAL_API_KEY=phx_your_personal_api_key
    HOG_PROJECT_ID=12345
    # EU Cloud only
    HOG_HOST=https://eu.posthog.com

    posthog-cli reads the POSTHOG_CLI_API_KEY, POSTHOG_CLI_PROJECT_ID, and POSTHOG_CLI_HOST names instead. The upload scripts still pass those names to hog for now, with a warning to rename them. While native symbol uploads run posthog-cli, keep both sets of names in the file.

    1. Android: Update the /android/app/build.gradle file from your app's root directory so that it looks like this:
    diff
    ...
    // This must be placed directly above the following `android` block.
    +apply from: new File(["node", "--print", "require('path').join(require('path').dirname(require.resolve('posthog-react-native')), '..', 'tooling', 'posthog.gradle')"].execute().text.trim())
    android {
    ...
    }
    1. iOS: Update the /ios/$yourProjectName.xcodeproj/project.pbxproj file (replace $yourProjectName with your project's actual name). You need to locate the Bundle React Native code and images build step.

    To do this through Xcode, open your project in Xcode, go to the project settings, navigate to Build Phases, and select Bundle React Native code and images. Use the command that matches your installed posthog-react-native version.

    posthog-react-native 4.61.0 and earlier

    diff
    ...
    -`"$NODE_BINARY" --print "require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'"`
    +/bin/sh `"$NODE_BINARY" --print "require('path').join(require('path').dirname(require.resolve('posthog-react-native')), '..', 'tooling', 'posthog-xcode.sh')"` `"$NODE_BINARY" --print "require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'"`

    posthog-react-native newer than 4.61.0

    diff
    ...
    -`"$NODE_BINARY" --print "require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'"`
    +`"$NODE_BINARY" --print "require('path').join(require('path').dirname(require.resolve('posthog-react-native')), '..', 'tooling', 'posthog-xcode.sh')"` `"$NODE_BINARY" --print "require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'"`

    If 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 run hog, which are not allowed under Xcode's script sandbox.

  5. Native crash symbolication

    Optional

    The steps above upload JavaScript source maps, which symbolicate exceptions thrown in your JS/TS code (including Hermes bytecode). They do not cover native iOS and Android crashes.

    If you enable native crash autocapture (errorTracking.autocapture.nativeCrashes, errorTracking.autocapture.androidNdkCrashes, or both), you also need to upload native debug symbols at build time so those crash reports are readable. This reuses the native PostHog SDKs' own tooling:

    PlatformCrashesSymbolsUploaded by
    iOSAll native crashes (nativeCrashes)dSYMsposthog-ios's upload-symbols.sh. The posthog-ios 3.x version that @posthog/react-native-plugin installs runs posthog-cli
    AndroidJava/Kotlin crashes (nativeCrashes)ProGuard/R8 mapping files, for minified release buildsThe com.posthog.android Gradle plugin, which uploads with hog from 1.9.0 and also injects a matching map-id into the app
    AndroidC/C++ (NDK) crashes (androidNdkCrashes).so debug symbolsThe same Gradle plugin

    Source-code context

    includeSource (or POSTHOG_INCLUDE_SOURCE on iOS) also uploads your native source files. On iOS, crash frames then show the surrounding code. On Android, it uploads your C/C++ sources with the .so debug symbols. Java/Kotlin crashes have no source-code context, because the ProGuard/R8 mapping upload doesn't include sources.

    Three pieces are required end-to-end

    Symbolicated native crashes need all three of these working together:

    1. Build-time – upload native symbols (this section).
    2. Runtime – enable errorTracking.autocapture.nativeCrashes (and errorTracking.autocapture.androidNdkCrashes for Android NDK crashes) and install @posthog/react-native-plugin.
    3. Server-side – enable the Enable exception autocapture setting in your project's error tracking settings.

    Prerequisites

    JavaScript source maps upload with hog from posthog-react-native 4.90.0, but native symbol uploads use the native SDKs' tooling, which picks its own CLI:

    • iOS dSYMs: @posthog/react-native-plugin 3.0 installs posthog-ios 4.2.x, whose upload-symbols.sh uploads with hog from 4.2.4. Plugin 2.x installs posthog-ios 3.x, which runs only posthog-cli.
    • Android, bare React Native: the Gradle plugin uploads with hog from 1.9.0. Earlier versions run posthog-cli.
    • Android, Expo: from posthog-react-native 4.90.0, the config plugin adds Gradle plugin 1.9.0, which uploads with hog. Earlier versions add 1.8.0, which runs only posthog-cli.

    Where a native upload runs posthog-cli, keep posthog-cli installed and logged in next to hog: npm install -g @posthog/cli, then posthog-cli login. The Android .so debug symbol upload needs posthog-cli 0.7.32 or later.

    In CI/CD builds (such as EAS Build), set HOG_PERSONAL_API_KEY and HOG_PROJECT_ID (and HOG_HOST for EU) for hog. posthog-cli reads only POSTHOG_CLI_API_KEY, POSTHOG_CLI_PROJECT_ID, and POSTHOG_CLI_HOST, so set both sets from the same secrets while native uploads run posthog-cli. The job's OIDC token in GitHub Actions, GitLab.com, and Depot CI only covers the uploads that run hog. See the migration guide for the full list of names.

    For local builds, log in with both hog auth login and posthog-cli login. To supply credentials from a file instead, use the dotenvFile plugin option described in the Upload step. It covers the native symbol uploads on both platforms too. On bare React Native, you get the same behavior by adding posthog.dotenvFile=../.env to android/gradle.properties (relative paths resolve against the android/ directory; the mapping upload needs posthog-android-gradle-plugin 1.4.0 or later) and, on iOS, defining HOG_DOTENV_FILE and POSTHOG_CLI_DOTENV_FILE build settings (for example $(SRCROOT)/../.env) on your app target. posthog-cli reads only POSTHOG_CLI_DOTENV_FILE.

    The posthog-react-native/expo config plugin can wire up native symbol upload for you during prebuild. It's opt-in – set uploadNativeSymbols to true in your app.json:

    JSON
    {
    "expo": {
    "plugins": [
    ["posthog-react-native/expo", { "uploadNativeSymbols": true }]
    ]
    }
    }

    When enabled, expo prebuild adds an iOS dSYM-upload build phase and applies the com.posthog.android Gradle plugin on Android. From posthog-react-native 4.78.0, it also enables the plugin's Android .so debug symbol upload for NDK crashes. If your project was prebuilt earlier with a com.posthog:posthog-android-gradle-plugin classpath older than 1.5.0, the next prebuild bumps it.

    To additionally upload native source files, pass an options object instead of true. On iOS, this adds source-code context to crash frames. On Android, it bundles the C/C++ sources with the .so debug symbols, from posthog-react-native 4.78.0:

    JSON
    {
    "expo": {
    "plugins": [
    ["posthog-react-native/expo", { "uploadNativeSymbols": { "includeSource": true } }]
    ]
    }
    }
  6. Verify source maps upload

    Checkpoint
    Confirm that source maps are successfully uploaded to PostHog.Check symbol sets in PostHog

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.

Still have questions?

Was this page useful?