← All help articles

Error tracking

Readable stack traces: upload source maps for Next.js on Vercel, Expo and Android

Minified stack traces are unreadable, and uploading your source maps lets PostHog show your real file names and line numbers instead.

  1. Your build produces source maps (JavaScript) or mapping files (Android ProGuard/R8).

  2. An ID is injected into the code you ship: a //# chunkId= comment in JavaScript, a map ID on Android.

  3. The maps are uploaded to PostHog, which matches them to incoming exceptions by that ID.

The personal API key you use for uploads is a secret. Keep it in environment variables and never commit it to your repository.

Next.js on Vercel

  1. Install the PostHog Next.js config package.

    ``shell npm install @posthog/nextjs-config ``

  2. Wrap your Next.js config with withPostHogConfig in next.config.ts.

    ```ts import { withPostHogConfig } from "@posthog/nextjs-config";

    const nextConfig = { //...your nextjs config, };

    export default withPostHogConfig(nextConfig, { personalApiKey: process.env.POSTHOG_API_KEY!, // Personal API Key projectId: process.env.POSTHOG_PROJECT_ID, // Project ID host: process.env.NEXT_PUBLIC_POSTHOG_HOST, // (optional), defaults to https://us.posthog.com sourcemaps: { // (optional) enabled: true, // (optional) Enable sourcemaps generation and upload, default to true on production builds releaseName: "my-application", // (optional) Release name, defaults to repository name releaseVersion: "1.0.0", // (optional) Release version, defaults to current git commit deleteAfterUpload: true, // (optional) Delete sourcemaps after upload, defaults to true }, }); ```

    If you use next.config.js instead, drop the ! after process.env.POSTHOG_API_KEY.

  3. Add these environment variables to your Vercel project settings, not just your local setup.

    • POSTHOG_API_KEY: a personal API key with at least write access on error tracking.

    • POSTHOG_PROJECT_ID: your project ID, shown in your project settings.

    • NEXT_PUBLIC_POSTHOG_HOST: your PostHog instance URL. It defaults to https://us.posthog.com.

  4. Build your app with next build. The package injects and uploads the source maps during the build. It doesn't upload with next dev.

  5. Serve the files from that build in production. In your browser's dev tools, each served file should contain a comment like this:

    ``js //# chunkId=0197e6db-9a73-7b91-9e80-4e1b7158db5c ``

React Native and Expo

  1. Install the PostHog CLI, version 0.7.8 or later. Curl, Homebrew and Cargo installs also work.

    ``bash npm install -g @posthog/cli ``

  2. In metro.config.js in your app's root folder, swap Expo's default Metro config for PostHog's. This needs Expo 50 or later.

    ```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 ```

  3. Add the posthog-react-native/expo plugin under expo.plugins in app.json. Expo plugins work only with prebuild and managed EAS Build.

    ```diff { "expo": { ... "plugins": [ ...

    • "posthog-react-native/expo" ] } } ```

  4. If your project has a checked-in ios/ folder, rerun the iOS prebuild.

    ``bash npx expo prebuild --platform ios ``

  5. Set these environment variables where your build runs, for example in EAS Build or your CI. POSTHOG_CLI_API_KEY is a personal API key with error tracking write and organization read scopes. On your own machine, you can run posthog-cli login instead.

    ```bash POSTHOG_CLI_API_KEY=phx_your_personal_api_key POSTHOG_CLI_PROJECT_ID=12345

    EU Cloud only

    POSTHOG_CLI_HOST=https://eu.posthog.com ```

  6. Run a native build. Gradle (Android) and Xcode (iOS) upload the source maps automatically.

  7. If you ship over-the-air updates with EAS Update, upload the source maps yourself after each update. dist is the default output folder for EAS updates.

    ```bash

    After running eas update or npx expo export --dump-sourcemap, upload source maps from the output directory

    posthog-cli hermes upload --directory dist ```

Not using the Expo plugin? Follow the manual Gradle and Xcode steps in PostHog's React Native source map docs instead.

Android (ProGuard/R8)

  1. Install the PostHog CLI, version 0.7.4 or later.

    ``bash npm install -g @posthog/cli ``

  2. Add the PostHog Android Gradle plugin to your app's build.gradle.kts. This needs Android Gradle Plugin (AGP) 8 or later. Replace $version with the plugin version you want to use.

    ``kotlin // Available through mavenCentral() plugins { id("com.android.application") id("com.posthog.android") version "$version" ... } ``

  3. Set POSTHOG_CLI_API_KEY, POSTHOG_CLI_PROJECT_ID and, on EU Cloud, POSTHOG_CLI_HOST where your build runs, as for Expo above. On your own machine, you can run posthog-cli login instead. In CI, you can also set them on the Gradle task:

    ```kotlin import com.posthog.android.PostHogCliExecTask

    tasks.withType<PostHogCliExecTask> { postHogHost = "https://eu.posthog.com" postHogProjectId = "my-project-id" postHogApiKey = "my-personal-api-key" } ```

  4. Build your minified release with Gradle. The plugin uploads the mapping files during the build and injects a matching map ID into your app.

Version requirements, as of the docs snapshot of 31 Oct 2026:

  • React Native and Expo: PostHog CLI 0.7.8 or later.

  • Android mappings: PostHog CLI 0.7.4 or later and AGP 8 or later.

  • Automatic injection on React Native: Expo 50 or later.

Check it in PostHog

  1. Open Error tracking and click the Configuration tab.

    The Error tracking page with the Configuration tab highlighted
  2. Click Symbol sets in the list on the left.

    Error tracking configuration with Symbol sets highlighted in the settings list, showing the symbol sets table
  3. Check the Status column. Uploaded means PostHog has the map. Missing means PostHog saw minified code for that file but has no map; hover over it to see why.

    A symbol set marked Missing, with the tooltip "No source map file has been uploaded"

Maps you upload later only apply to exceptions that arrive after the upload.

Common problems

The status shows Missing. Upload the maps before you deploy the code that uses them, and upload them to the right project. Serve the injected files: if you serve copies from before the injection, PostHog can't match them. Source map paths must match your production bundle URLs exactly.

Maps aren't uploaded from Vercel. Add the environment variables to your Vercel project settings, not only to your local setup. Uploads run on next build, not on next dev.

The CLI says Server returned 0 upload keys (1 skipped as already present). A symbol set with the same chunk ID already exists. The ID comes from the bundle's content, so unchanged code gets the same ID. Make a real code change (not just whitespace) and rebuild, or delete the old symbol set:

  1. In Symbol sets, click the trash icon (Delete symbol set) on the symbol set's row.

    The Delete symbol set button highlighted on a row of the symbol sets table
  2. Confirm the deletion, then rebuild your app.

Stack traces from an EAS Update are still minified. Native builds upload automatically, but updates don't. Run posthog-cli hermes upload --directory dist after each eas update.

The iOS build fails with Sandbox: bash deny(1) file-read-data. The plugin option { disableSandboxing: false } or ENABLE_USER_SCRIPT_SANDBOXING = YES in your Xcode project keeps Xcode's script sandbox on. Remove the opt-out, or declare inputs on every build-phase script and keep sandboxing on.