Nuxt error tracking installation
For Nuxt v3.7 and above, we recommend using the official @posthog/nuxt
module which provides automatic error tracking with built-in source map support.
- 1
Install the PostHog Nuxt module
RequiredYour goal in this step: Install and configure the PostHog Nuxt module.Install the PostHog Nuxt module using your package manager:
Add the module to your
nuxt.config.ts
file:nuxt.config.tsThe module will automatically:
- Initialize PostHog on both Vue (client side) and Nitro (server side)
- Capture exceptions on both client and server
- Generate and upload source maps during build
- 2
Manually capturing exceptions
OptionalYour goal in this step: Manually capture exceptions in your Nuxt application.Our module if set up as shown above already captures both client and server side exceptions automatically.
To send errors manually on the client side, import it and use the
captureException
method like this:VueOn the server side instantiate PostHog using:
server/api/example.js - 3
Build your project for production
RequiredBuild your project for production by running the following command:
TerminalThe PostHog module will automatically generate and upload source maps to PostHog during the build process.
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.map
source map files for//# chunkId=
comments. Make sure to serve these injected files in production, PostHog will check for the//# chunkId
comments to display the correct stack traces.