Star us on GitHub
Star
Menu

Nuxt Integration

Nuxt Integration with Highlight

Easily add Session Replay, Error Monitoring, and more to your Nuxt 3 app with Highlight.


🚀 Quick Start


1. Prerequisites

  • Nuxt 3 project
  • Access to your Highlight project ID (get one here)

2. Client-side Instrumentation

Create plugins/highlight.client.ts:

import { H } from "highlight.run"; export default defineNuxtPlugin((nuxtApp) => { const { projectID, version } = useRuntimeConfig().highlight; nuxtApp.hook("app:beforeMount", () => { H.init(projectID, { environment: process.env.NODE_ENV, version, networkRecording: { enabled: true, recordHeadersAndBody: true, }, tracingOrigins: true, consoleMethodsToRecord: ["error", "warn"], }); }); });
Copy

3. Server-side Instrumentation

Create server/plugins/highlight.ts:

import { H, type NodeOptions } from "@highlight-run/node" export default defineNitroPlugin((nitro) => { const { projectID } = useRuntimeConfig().highlight; const highlightConfig: NodeOptions = { projectID }; if (!H.isInitialized()) { H.init(highlightConfig) } nitro.hooks.hook("error", async (error, { event }) => { const headers = event?.node.req.headers! const parsed = H.parseHeaders(headers) if (parsed !== undefined) { H.consumeError(error, parsed?.secureSessionId, parsed?.requestId) } }) })
Copy

4. Configure nuxt.config.ts

export default defineNuxtConfig({ runtimeConfig: { highlight: { projectID: 'YOUR_PROJECT_ID', version: '1.0.0', } } })
Copy

To get readable stack traces in Highlight, upload your sourcemaps after each build. See the Highlight sourcemap documentation for details.

6. Verifying Installation

7. Manual Error Reporting (Optional)

If you want to capture errors that are not automatically caught by Nitro, you can manually report them:

import { H } from "@highlight-run/node"; try { // your code } catch (error) { H.consumeError(error); }
Copy

8. Troubleshooting

  • Session IDs undefined: Ensure the client SDK is initialized and all relevant headers are forwarded to the server (especially if using a reverse proxy or custom server).
  • Sourcemaps not working: Confirm sourcemaps are uploaded and not stripped from your build output.
  • Not all errors captured: Only errors caught by the Nitro error hook are sent automatically. Use manual error reporting for custom error handling.
  • Nuxt plugin not running: Double-check file placement (plugins/highlight.client.ts for client, server/plugins/highlight.ts for server) and that plugins are auto-registered.
  • Environment variables: Use Nuxt's runtimeConfig for secrets and project IDs.

9. References