Build Options
Learn about configuration options used in your Next.js configuration to control your app's build process.
The Sentry Next.js SDK supports automatic code injection and source map upload during your app's build process using the withSentryConfig wrapper in your Next.js configuration file (next.config.js or next.config.mjs). For information on updating the configuration, see Extend Next.js Configuration.
org
| Type | string |
|---|
The slug of the Sentry organization associated with the app.
project
| Type | string |
|---|
The slug of the Sentry project associated with the app.
authToken
| Type | string |
|---|
The authentication token to use for all communication with Sentry. Can be obtained from https://sentry.io/orgredirect/organizations/:orgslug/settings/auth-tokens/.
sentryUrl
| Type | string |
|---|---|
| Default | https://sentry.io/ |
The base URL of your Sentry instance. Use this if you are using a self-hosted or Sentry instance other than sentry.io.
headers
| Type | Record<string, string> |
|---|
Headers added to every outgoing network request.
telemetry
| Type | boolean |
|---|---|
| Default | true |
If set to true, internal plugin errors and performance data will be sent to Sentry.
At Sentry we like to use Sentry ourselves to deliver faster and more stable products. We're very careful of what we're sending. We won't collect anything other than error and high-level performance data. We will never collect your code or any details of the projects in which you're using this plugin.
silent
| Type | boolean |
|---|---|
| Default | false |
Suppresses all Sentry SDK build logs.
debug
| Type | boolean |
|---|---|
| Default | false |
Prints additional debug information about the SDK and uploading source maps when building the application.
errorHandler
| Type | (error: Error) => void |
|---|
A callback function that will be invoked when errors occur during the Sentry build process. This is particularly useful for gracefully handling CI/CD pipeline failures when there are connectivity issues. You can optionally re-throw the error to fail the build process.
withSentryConfig(nextConfig, {
// ... other options
errorHandler: (error) => {
console.warn("Sentry build error occurred:", error);
// Optionally, you can still fail the build by re-throwing the error
// throw error;
},
});
sourcemaps.disable
| Type | boolean |
|---|
Disable any functionality related to source maps.
sourcemaps.assets
| Type | string | string[] |
|---|
A glob or an array of globs that specifies the build artifacts that should be uploaded to Sentry. If not specified, the plugin will try to upload all JavaScript files and source map files created during build.
The globbing patterns follow the implementation of the glob package.
sourcemaps.ignore
| Type | string | string[] |
|---|---|
| Default | [] |
A glob or an array of globs that specifies which build artifacts should not be uploaded to Sentry.
sourcemaps.deleteSourcemapsAfterUpload
| Type | boolean |
|---|---|
| Default | true |
Toggle whether generated source maps within your Next.js build folder should be automatically deleted after being uploaded to Sentry.
release.name
| Type | string |
|---|
Unique identifier for the release you want to create. Defaults to automatically detecting a value for your environment.
release.create
| Type | boolean |
|---|---|
| Default | true |
Whether the plugin should create a release on Sentry during the build.
release.finalize
| Type | boolean |
|---|---|
| Default | true |
Whether the Sentry release should be automatically finalized after the build ends.
release.dist
| Type | string |
|---|
Unique identifier for the distribution, used to further segment your release. Usually your build number.
bundleSizeOptimizations.excludeDebugStatements
| Type | boolean |
|---|
If set to true, the Sentry SDK will attempt to tree-shake any debugging code within itself during the build.
bundleSizeOptimizations.excludeTracing
| Type | boolean |
|---|
If set to true, the Sentry SDK will attempt to tree-shake code related to tracing and performance monitoring.
Notice: Do not enable this when using any performance monitoring-related SDK features.
widenClientFileUpload
| Type | boolean |
|---|---|
| Default | false |
Include Next.js-internal code and code from dependencies when uploading source maps.
Note: Enabling this option can lead to longer build times.
autoInstrumentServerFunctions
| Type | boolean |
|---|---|
| Default | true |
Automatically instrument Next.js data fetching methods and Next.js API routes with error and performance monitoring.
autoInstrumentMiddleware
| Type | boolean |
|---|---|
| Default | true |
Automatically instrument Next.js middleware with error and performance monitoring.
autoInstrumentAppDirectory
| Type | boolean |
|---|---|
| Default | true |
Automatically instrument components in the app directory with error monitoring.
excludeServerRoutes
| Type | Array<RegExp | string> |
|---|
Exclude specific server-side API routes or pages from automatic Sentry instrumentation during build time. This option takes an array of strings or regular expressions and affects pages in the pages and app directories.
When defining routes, note the following:
- Specify pages as routes and not as file system paths. For example, write
/animalsinstead ofpages/animals/index.js. - Make sure that any provided string matches the route exactly, has a leading slash, and doesn't have a trailing slash.
excludeServerRoutes: [
"/some/excluded/route",
"/excluded/route/with/[parameter]",
/^\/route\/beginning\/with\/some\/prefix/,
/\/routeContainingASpecificPathSegment\/?/,
];
If you're building your Next.js application with Turbopack, this option will have no effect. The Sentry SDK will no longer apply build-time instrumentation and will rely purely on Next.js telemetry features.
tunnelRoute
| Type | string | boolean |
|---|
This feature requires Next.js version 11+ and doesn't currently work with self-hosted Sentry instances.
Tunnel Sentry requests through this route on your Next.js server to prevent ad-blockers from blocking Sentry events from being sent.
This option can be set to:
truefor auto-generated routes, which are unpredictable and change with each deployment.- A custom static string path like
/error-monitoring.
Learn more about tunneling in the troubleshooting section.
automaticVercelMonitors
| Type | boolean |
|---|---|
| Default | false |
Automatically create cron monitors in Sentry for your Vercel Cron Jobs if configured via vercel.json.
disableManifestInjection
| Type | boolean|undefined |
|---|---|
| Default | false |
Disables automatic injection of the route manifest into the client bundle.
The route manifest is a build-time generated mapping of your Next.js App Router routes that enables Sentry to group transactions by parameterized route names (e.g., /users/:id instead of /users/123, /users/456, etc.).
Disable this option if:
- You want to minimize client bundle size
- You're experiencing build issues related to route scanning
- You prefer raw URLs in transaction names
- You're only using the Pages Router (this feature is only supported in the App Router)
reactComponentAnnotation.enabled
| Type | boolean |
|---|---|
| Default | false |
Enables React component name tracking. When enabled, it annotates React components with data attributes that allow Sentry to track which components users interacted with in features like Session Replay and breadcrumbs.
reactComponentAnnotation.ignoredComponents
| Type | string[] | undefined |
|---|
A list of React component names to exclude from component annotation.
useRunAfterProductionCompileHook
| Type | boolean |
|---|---|
| Default | false(webpack)|true(turbopack) |
Version support
You can use this option with Next.js version 15.4.1 and later.
Enables the use of the runAfterProductionCompile hook from Next.js to upload sourcemaps after the build is completed.
- This option is set to
trueby default for Turbopack as there are no alternative ways to upload sourcemaps here. - This option is set to
falsefor Webpack as the default behavior is to upload sourcemaps during the build process using the Sentry Webpack Plugin.
Important: Enabling this option will mutate your Next.js build output by injecting Debug IDs via the Sentry CLI. If you are relying on any sort of integrity hashes for your build artifacts, you will need to disable this option.
unstable_sentryWebpackPluginOptions
| Type | SentryWebpackPluginOptions |
|---|
Pass configuration options directly to the Sentry Webpack Plugin that ships with the Sentry Next.js SDK. If withSentryConfig doesn't provide the option you need to modify, you may override the sentryWebpackPluginOptions using this option.
Important
This option is considered unstable, and its API may change in a breaking way in any release.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").