Skip to content

Commit 3fdab04

Browse files
authored
feat: Warn about source-map generation (#14533)
1 parent e17bd91 commit 3fdab04

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

packages/astro/src/integration/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
3535

3636
// We don't need to check for AUTH_TOKEN here, because the plugin will pick it up from the env
3737
if (shouldUploadSourcemaps && command !== 'dev') {
38+
// TODO(v9): Remove this warning
39+
if (config?.vite?.build?.sourcemap === false) {
40+
logger.warn(
41+
"You disabled sourcemaps with the `vite.build.sourcemap` option. Currently, the Sentry SDK will override this option to generate sourcemaps. In future versions, the Sentry SDK will not override the `vite.build.sourcemap` option if you explicitly disable it. If you want to generate and upload sourcemaps please set the `vite.build.sourcemap` option to 'hidden' or undefined.",
42+
);
43+
}
44+
45+
// TODO: Add deleteSourcemapsAfterUpload option and warn if it isn't set.
46+
3847
updateConfig({
3948
vite: {
4049
build: {

packages/nextjs/src/config/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ export type IgnoreWarningsOption = (
470470
// The two possible formats for providing custom webpack config in `next.config.js`
471471
export type WebpackConfigFunction = (config: WebpackConfigObject, options: BuildContext) => WebpackConfigObject;
472472
export type WebpackConfigObject = {
473-
devtool?: string;
473+
devtool?: string | boolean;
474474
plugins?: Array<WebpackPluginInstance>;
475475
entry: WebpackEntryProperty;
476476
output: { filename: string; path: string };

packages/nextjs/src/config/webpack.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,33 @@ export function constructWebpackConfigFunction(
336336

337337
if (sentryWebpackPlugin) {
338338
if (!userSentryOptions.sourcemaps?.disable) {
339+
// TODO(v9): Remove this warning
340+
if (newConfig.devtool === false) {
341+
const runtimePrefix = !isServer ? 'Client' : runtime === 'edge' ? 'Edge' : 'Node.js';
342+
// eslint-disable-next-line no-console
343+
console.warn(
344+
`[@sentry/nextjs - ${runtimePrefix}] You disabled sourcemaps with the Webpack \`devtool\` option. Currently, the Sentry SDK will override this option to generate sourcemaps. In future versions, the Sentry SDK will not override the \`devtool\` option if you explicitly disable it. If you want to generate and upload sourcemaps please set the \`devtool\` option to 'hidden-source-map' or undefined.`,
345+
);
346+
}
347+
348+
// TODO(v9): Remove this warning and print warning in case source map deletion is auto configured
349+
if (!isServer && !userSentryOptions.sourcemaps?.deleteSourcemapsAfterUpload) {
350+
// eslint-disable-next-line no-console
351+
console.warn(
352+
"[@sentry/nextjs] The Sentry SDK has enabled source map generation for your Next.js app. If you don't want to serve Source Maps to your users, either set the `deleteSourceMapsAfterUpload` option to true, or manually delete the source maps after the build. In future Sentry SDK versions `deleteSourceMapsAfterUpload` will default to `true`.",
353+
);
354+
}
355+
339356
// `hidden-source-map` produces the same sourcemaps as `source-map`, but doesn't include the `sourceMappingURL`
340357
// comment at the bottom. For folks who aren't publicly hosting their sourcemaps, this is helpful because then
341358
// the browser won't look for them and throw errors into the console when it can't find them. Because this is a
342359
// front-end-only problem, and because `sentry-cli` handles sourcemaps more reliably with the comment than
343360
// without, the option to use `hidden-source-map` only applies to the client-side build.
344-
newConfig.devtool =
345-
isServer || userNextConfig.productionBrowserSourceMaps ? 'source-map' : 'hidden-source-map';
361+
if (isServer || userNextConfig.productionBrowserSourceMaps) {
362+
newConfig.devtool = 'source-map';
363+
} else {
364+
newConfig.devtool = 'hidden-source-map';
365+
}
346366
}
347367

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

packages/solidstart/src/vite/sourceMaps.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@ export function makeSourceMapsVitePlugin(options: SentrySolidStartPluginOptions)
1515
apply: 'build',
1616
enforce: 'post',
1717
config(config) {
18-
const sourceMapsPreviouslyNotEnabled = !config.build?.sourcemap;
19-
if (debug && sourceMapsPreviouslyNotEnabled) {
18+
// TODO(v9): Remove this warning
19+
if (config.build?.sourcemap === false) {
2020
// eslint-disable-next-line no-console
21-
console.log('[Sentry SolidStart Plugin] Enabling source map generation');
22-
if (!sourceMapsUploadOptions?.filesToDeleteAfterUpload) {
23-
// eslint-disable-next-line no-console
24-
console.warn(
25-
`[Sentry SolidStart PLugin] We recommend setting the \`sourceMapsUploadOptions.filesToDeleteAfterUpload\` option to clean up source maps after uploading.
26-
[Sentry SolidStart Plugin] Otherwise, source maps might be deployed to production, depending on your configuration`,
27-
);
28-
}
21+
console.warn(
22+
"[Sentry SolidStart Plugin] You disabled sourcemaps with the `build.sourcemap` option. Currently, the Sentry SDK will override this option to generate sourcemaps. In future versions, the Sentry SDK will not override the `build.sourcemap` option if you explicitly disable it. If you want to generate and upload sourcemaps please set the `build.sourcemap` option to 'hidden' or undefined.",
23+
);
2924
}
25+
26+
// TODO(v9): Remove this warning and print warning in case source map deletion is auto configured
27+
if (!sourceMapsUploadOptions?.filesToDeleteAfterUpload) {
28+
// eslint-disable-next-line no-console
29+
console.warn(
30+
"[Sentry SolidStart Plugin] The Sentry SDK has enabled source map generation for your SolidStart app. If you don't want to serve Source Maps to your users, either configure the `filesToDeleteAfterUpload` option with a glob to remove source maps after uploading them, or manually delete the source maps after the build. In future Sentry SDK versions source maps will be deleted automatically after uploading them.",
31+
);
32+
}
33+
3034
return {
3135
...config,
3236
build: {

0 commit comments

Comments
 (0)