Upload source maps for Next.js
- 1
Install the PostHog Next.js config package
RequiredTerminal - 2
Add PostHog config to your Next.js app
RequiredAdd the following to your
next.config.js
file:next.config.jsWhere you should set the following environment variables:
Environment Variable Description POSTHOG_API_KEY
Personal API key with at least write
access onerror tracking
POSTHOG_ENV_ID
Project ID you can find in your project settings NEXT_PUBLIC_POSTHOG_HOST
Your PostHog instance URL. Defaults to https://us.posthog.com
If you are using Vercel (or any other hosting service), make sure these environment variables are added to your project settings, not just your local setup. This enables source maps to be automatically uploaded on your production build.
Verify source map generation
CheckpointBefore proceeding, confirm that source maps are being generated by checking for
.js.map
files in yourdist
directory. These are the symbol sets that will be used to unminify stack traces in PostHog.- 3
Inject and upload source maps
RequiredThe Next.js config package automatically handles source map injection and upload during the build process. No additional configuration is needed.Make sure you serve the injected files in production by running the same build and inject process in CI during deployment. PostHog will need access to these injected
chunkId
comments when building the stack traces.