Upload source maps for Nuxt
Contents
Nuxt v3.7 and above
For Nuxt v3.7 and above, the @posthog/nuxt module automatically handles source map generation and upload during the build process.
No manual configuration is needed - follow the Nuxt error tracking installation guide to set up the module, and source maps are automatically generated and uploaded when you build your project.
Nuxt v3.6 and below
For older versions of Nuxt, you'll need to manually configure source map generation and upload using the PostHog CLI.
- 1
Install the PostHog CLI
RequiredInstall
posthog-cli: - 2
Authenticate the PostHog CLI
RequiredTo authenticate the CLI, you can call the
logincommand and follow the instructions:TerminalIf you are using the CLI in a CI/CD environment such as GitHub Actions, you can set environment variables to authenticate:
Environment Variable Description Source POSTHOG_CLI_ENV_IDPostHog project ID Environment settings POSTHOG_CLI_TOKENPersonal API key with error tracking writescopeAPI key settings Use the
--hostoption in subsequent commands to specify a different PostHog instance / or region. For EU users:Terminal - 3
Generate source maps during build
RequiredYou can hook into the
closeevent to generate and upload source maps for your Nuxt application like this:nuxt.config.js - 4
Build your project for production
RequiredBuild your project for production by running the following command:
TerminalPost-build scripts should automatically generate and upload source maps to PostHog.
Verify source map upload
CheckpointConfirm source maps are being properly uploadedBefore proceeding, confirm that source maps are being properly uploaded.
You can verify the injection is successful by checking your
.mjs.mapsource map files for//# chunkId=comments. Make sure to serve these injected files in production, PostHog will check for the//# chunkIdcomments to display the correct stack traces.- 5
Next steps
After configuring PostHog, update your build and deployment process to serve bundles injected with the
chunkIdcomments. PostHog relies on these comments to display the correct stack traces. Remember to export the required environment variables in your deployment process.