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.
Your build produces source maps (JavaScript) or mapping files (Android ProGuard/R8).
An ID is injected into the code you ship: a
//# chunkId=comment in JavaScript, a map ID on Android.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
Install the PostHog Next.js config package.
``
shell npm install @posthog/nextjs-config``Wrap your Next.js config with
withPostHogConfiginnext.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.jsinstead, drop the!afterprocess.env.POSTHOG_API_KEY.Add these environment variables to your Vercel project settings, not just your local setup.
POSTHOG_API_KEY: a personal API key with at leastwriteaccess onerror tracking.POSTHOG_PROJECT_ID: your project ID, shown in your project settings.NEXT_PUBLIC_POSTHOG_HOST: your PostHog instance URL. It defaults tohttps://us.posthog.com.
Build your app with
next build. The package injects and uploads the source maps during the build. It doesn't upload withnext dev.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
Install the PostHog CLI, version 0.7.8 or later. Curl, Homebrew and Cargo installs also work.
``
bash npm install -g @posthog/cli``In
metro.config.jsin 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 ```
Add the
posthog-react-native/expoplugin underexpo.pluginsinapp.json. Expo plugins work only with prebuild and managed EAS Build.```diff { "expo": { ... "plugins": [ ...
"posthog-react-native/expo" ] } } ```
If your project has a checked-in
ios/folder, rerun the iOS prebuild.``
bash npx expo prebuild --platform ios``Set these environment variables where your build runs, for example in EAS Build or your CI.
POSTHOG_CLI_API_KEYis a personal API key witherror tracking writeandorganization readscopes. On your own machine, you can runposthog-cli logininstead.```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 ```
Run a native build. Gradle (Android) and Xcode (iOS) upload the source maps automatically.
If you ship over-the-air updates with EAS Update, upload the source maps yourself after each update.
distis the default output folder for EAS updates.```bash
After running
eas updateornpx expo export --dump-sourcemap, upload source maps from the output directoryposthog-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)
Install the PostHog CLI, version 0.7.4 or later.
``
bash npm install -g @posthog/cli``Add the PostHog Android Gradle plugin to your app's
build.gradle.kts. This needs Android Gradle Plugin (AGP) 8 or later. Replace$versionwith the plugin version you want to use.``
kotlin // Available through mavenCentral() plugins { id("com.android.application") id("com.posthog.android") version "$version" ... }``Set
POSTHOG_CLI_API_KEY,POSTHOG_CLI_PROJECT_IDand, on EU Cloud,POSTHOG_CLI_HOSTwhere your build runs, as for Expo above. On your own machine, you can runposthog-cli logininstead. 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" } ```
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
Open Error tracking and click the Configuration tab.

Click Symbol sets in the list on the left.

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.

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:
In Symbol sets, click the trash icon (Delete symbol set) on the symbol set's row.

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.