From d9562b9499e8497250dfbea9091035abf355e1d3 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 29 May 2024 17:14:55 +0200 Subject: [PATCH] fix(nextjs): Do not hide `sourceMappingURL` comment on client when `nextConfig.productionBrowserSourceMaps: true` is set (#12278) --- packages/nextjs/src/config/types.ts | 1 + packages/nextjs/src/config/webpack.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/nextjs/src/config/types.ts b/packages/nextjs/src/config/types.ts index 57601279997c..b6207b8d67f9 100644 --- a/packages/nextjs/src/config/types.ts +++ b/packages/nextjs/src/config/types.ts @@ -48,6 +48,7 @@ export type NextConfigObject = { instrumentationHook?: boolean; clientTraceMetadata?: string[]; }; + productionBrowserSourceMaps?: boolean; }; export type SentryBuildOptions = { diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 14cdad42a25e..44537ede59f8 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -329,7 +329,8 @@ export function constructWebpackConfigFunction( // the browser won't look for them and throw errors into the console when it can't find them. Because this is a // front-end-only problem, and because `sentry-cli` handles sourcemaps more reliably with the comment than // without, the option to use `hidden-source-map` only applies to the client-side build. - newConfig.devtool = !isServer ? 'hidden-source-map' : 'source-map'; + newConfig.devtool = + isServer || userNextConfig.productionBrowserSourceMaps ? 'source-map' : 'hidden-source-map'; } newConfig.plugins = newConfig.plugins || [];