Skip to content

Commit cf6643b

Browse files
committed
only apply option to client-side builds
1 parent 358eaae commit cf6643b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,16 @@ export function constructWebpackConfigFunction(
7878
// TODO Handle possibility that user is using `SourceMapDevToolPlugin` (see
7979
// https://webpack.js.org/plugins/source-map-dev-tool-plugin/)
8080

81-
// Next doesn't let you change this is dev even if you want to - see
81+
// Next doesn't let you change `devtool` in dev even if you want to, so don't bother trying - see
8282
// https://github.com/vercel/next.js/blob/master/errors/improper-devtool.md
8383
if (!buildContext.dev) {
84-
newConfig.devtool = userNextConfig.sentry?.hideSourceMaps ? 'hidden-source-map' : 'source-map';
84+
// `hidden-source-map` produces the same sourcemaps as `source-map`, but doesn't include the `sourceMappingURL`
85+
// comment at the bottom. For folks who aren't publicly hosting their sourcemaps, this is helpful because then
86+
// the browser won't look for them and throw errors into the console when it can't find them. Because this is a
87+
// front-end-only problem, and because `sentry-cli` handles sourcemaps more reliably with the comment than
88+
// without, the option to use `hidden-source-map` only applies to the client-side build.
89+
newConfig.devtool =
90+
userNextConfig.sentry?.hideSourceMaps && !buildContext.isServer ? 'hidden-source-map' : 'source-map';
8591
}
8692

8793
newConfig.plugins = newConfig.plugins || [];

packages/nextjs/test/config.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,14 @@ describe('webpack config', () => {
300300
expect(finalWebpackConfig).toEqual(expect.objectContaining(materializedUserWebpackConfig));
301301
});
302302

303-
it('allows for the use of `hidden-source-map` as `devtool` value', async () => {
303+
it('allows for the use of `hidden-source-map` as `devtool` value for client-side builds', async () => {
304304
const userNextConfigHiddenSourceMaps = { ...userNextConfig, sentry: { ...userNextConfig.sentry } };
305305
userNextConfigHiddenSourceMaps.sentry.hideSourceMaps = true;
306306

307307
const finalWebpackConfig = await materializeFinalWebpackConfig({
308308
userNextConfig: userNextConfigHiddenSourceMaps,
309-
incomingWebpackConfig: serverWebpackConfig,
310-
incomingWebpackBuildContext: serverBuildContext,
309+
incomingWebpackConfig: clientWebpackConfig,
310+
incomingWebpackBuildContext: clientBuildContext,
311311
});
312312

313313
expect(finalWebpackConfig.devtool).toEqual('hidden-source-map');

0 commit comments

Comments
 (0)