Installation
Install with Wizard
The easiest way to set up Sentry in Next.js is using the Sentry Wizard:The wizard will:
- Install the
@sentry/nextjspackage - Create configuration files
- Set up source maps upload
- Configure build-time instrumentation
Version Compatibility
- Next.js 13.2+: Fully supported (App Router & Pages Router)
- Next.js 15+: Full support including Turbopack (beta)
- Next.js 16+: Turbopack default bundler support
Basic Setup
Client Configuration
Createsentry.client.config.ts (or .js) in your project root:
Server Configuration
Createsentry.server.config.ts (or .js) in your project root:
Edge Runtime Configuration
Createsentry.edge.config.ts (or .js) for Edge runtime:
Next.js Configuration
Wrap yournext.config.js with withSentryConfig:
- next.config.js
- next.config.mjs (ESM)
App Router Features
Server Components
Sentry automatically instruments Server Components:Route Handlers
Route handlers are automatically instrumented:Server Actions
Wrap Server Actions for error tracking:Pages Router Features
API Routes
Wrap API routes for automatic instrumentation:Data Fetching Methods
Custom Error Page
Create a custom error page with Sentry:Middleware Instrumentation
Environment Variables
Add these to your.env.local or deployment environment:
Performance Monitoring
Custom Transactions
Database Queries
Source Maps
Source maps are automatically uploaded during build when configured:Turbopack Support
For Next.js 15+ with Turbopack:Best Practices
Separate Configs
Use separate config files for client, server, and edge runtimes.
Source Maps
Always upload source maps for production builds.
Error Boundaries
Use React Error Boundaries in client components.
Environment Variables
Store sensitive data in environment variables.
Troubleshooting
Build Errors with Turbopack
Build Errors with Turbopack
If you encounter build errors with Turbopack:
- Ensure you’re using Next.js 15.6+
- Check that
@sentry/nextjsis up to date - Try disabling automatic instrumentation in
next.config.js
Source Maps Not Uploaded
Source Maps Not Uploaded
Verify:
SENTRY_AUTH_TOKENis setorgandprojectare correct inwithSentryConfigsilent: falseto see upload logs
Next Steps
App Router
Deep dive into App Router features
Server Actions
Track Server Actions and mutations
Middleware
Instrument Next.js middleware
Source Maps
Advanced source map configuration