Sentry Spotlight Sourcemaps Fail Under Turbopack In Next.Js
When using @sentry/nextjs with Next.js 16 and Turbopack dev mode, Sentry Spotlight cannot resolve stack traces to original source files despite enabling experimental sourcemap flags. Webpack dev mode works correctly with devtool: 'source-map'.
Turbopack's generated sourcemaps do not provide the expected source file paths or metadata for Sentry Spotlight to map minified chunks back to original sources, likely due to incomplete or incompatible sourcemap configuration between Turbopack and the Sentry SDK.
1. Create a Next.js app with @sentry/nextjs and the given next.config.ts. 2. Enable experimental.turbopackSourceMaps and turbopackInputSourceMaps. 3. Run `next dev` (Turbopack) and trigger an error. 4. Observe Sentry Spotlight shows minified chunk path instead of original src/app/page.tsx.
Fixing Code Block
import { withSentryConfig } from "@sentry/nextjs";
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
reactStrictMode: false,
experimental: {
// Use object form for finer control (Next.js 15.5+)
turbopackSourceMaps: {
include: ["**/*"],
},
turbopackInputSourceMaps: true,
},
webpack(config, { dev, isServer }) {
// Keep webpack dev mode working as before
if (dev && !isServer) {
config.devtool = "source-map";
}
return config;
},
};
export default withSentryConfig(nextConfig, {
org: process.env.SENTRY_ORGANIZATION,
project: process.env.SENTRY_PROJECT,
authToken: process.env.SENTRY_AUTH_TOKEN,
silent: !process.env.CI,
widenClientFileUpload: true,
webpack: {
reactComponentAnnotation: { enabled: true },
treeshake: { removeDebugLogging: true },
},
telemetry: false,
sourcemaps: {
disable: false,
// Ensure sourcemaps are not deleted during dev if any upload occurs
deleteSourcemapsAfterUpload: false,
},
});
The fix changes `experimental.turbopackSourceMaps` from boolean `true` to an object with `include: ['**/*']` to explicitly include all source files in generated sourcemaps, which may resolve path mapping issues. It also adds `deleteSourcemapsAfterUpload: false` to prevent Sentry from deleting sourcemap files during development, ensuring they remain available for Spotlight. The webpack devtool configuration is retained to keep Webpack mode functional.
Edge Case Audit
This configuration may not work on older Next.js versions that only accept boolean for turbopackSourceMaps (before 15.5). Upgrading to 15.5+ or 16 may introduce other breaking changes; test thoroughly. In production builds, sourcemaps increase build time and output size, so consider conditionally enabling only in dev. The `deleteSourcemapsAfterUpload` setting could leave stale sourcemap files if not cleaned up manually; ensure CI pipelines clean artifacts. Rollback by reverting to the original boolean `true` and removing the new Sentry sourcemap option.