@sentry/nuxt package provides comprehensive error tracking and performance monitoring for Nuxt applications, with support for both client and server environments.
Prerequisites
- Node.js 18.19.1 or newer
- Nuxt 3.7.0 or newer (3.14.0+ recommended) or Nuxt 4.x
- A Sentry account and project DSN
Nuxt 3.14.0+ is recommended for the best experience. Older versions are supported but may have limitations.
Installation
1
Install the Package
Install Current Version: 10.42.0
@sentry/nuxt using your preferred package manager:2
Register the Sentry Module
Add the Sentry module to your
nuxt.config.ts:3
Create Client Configuration
Create
sentry.client.config.ts in your project root:4
Create Server Configuration
Create
sentry.server.config.ts in your project root:5
Verify Installation
Create a test page to verify Sentry is working:Visit the page and click the button. Check your Sentry dashboard to see the error.
Configuration Options
Configure Sentry in yournuxt.config.ts:
Error Handling
Automatic Error Capture
The SDK automatically captures:- Unhandled exceptions on client and server
- Vue errors and warnings
- API errors
- Server middleware errors
Manual Error Capture
In Vue components:In Server API Routes
In Server Middleware
Performance Monitoring
Automatic Instrumentation
The SDK automatically creates spans for:- Page loads and navigation
- API requests
- Server routes
- Database queries (with integrations)
Custom Spans
In components:Setting Context
User Context
Tags and Extra Context
Breadcrumbs
Composables
useSentry Composable
Create a custom composable for easier Sentry usage:Session Replay
Configure Session Replay in your client config:Pinia Integration
Track Pinia store actions:Source Maps
Source maps are automatically uploaded when configured innuxt.config.ts:
Advanced Configuration
Environment Detection
Sampling
Filtering Events
Runtime Configuration
Use runtime config for dynamic DSN:Troubleshooting
Errors Not Captured
- Ensure the Sentry module is registered in
nuxt.config.ts - Check that both
sentry.client.config.tsandsentry.server.config.tsexist - Verify DSN is correct in both configs
Source Maps Not Working
- Check
SENTRY_AUTH_TOKENis set correctly - Verify
organdprojectmatch your Sentry organization - Ensure
sourceMapsUploadOptionsis configured
Performance Data Missing
- Ensure
tracesSampleRateis greater than 0 - Check that Sentry module is loaded before your app
- Verify Sentry is initialized in both client and server configs
Module Not Loading
If the Sentry module isn’t loading:- Update to the latest
@sentry/nuxtversion - Clear
.nuxtdirectory:rm -rf .nuxt - Reinstall dependencies
- Check Nuxt version compatibility
Next Steps
- Configure Vue Router Integration
- Set up Pinia Integration
- Learn about Session Replay
- Explore Performance Monitoring