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.jsfile:next.config.jsWhere you should set the following environment variables:
Environment Variable Description POSTHOG_API_KEYPersonal API key with at least writeaccess onerror trackingPOSTHOG_ENV_IDProject ID you can find in your project settings NEXT_PUBLIC_POSTHOG_HOSTYour PostHog instance URL. Defaults to https://us.posthog.comIf 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.mapfiles in yourdistdirectory. 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
chunkIdcomments when building the stack traces.