Skip to content

Commit

Permalink
feat: Warn about source-map generation (#14533)
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst authored Nov 29, 2024
1 parent e17bd91 commit 3fdab04
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
9 changes: 9 additions & 0 deletions packages/astro/src/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {

// We don't need to check for AUTH_TOKEN here, because the plugin will pick it up from the env
if (shouldUploadSourcemaps && command !== 'dev') {
// TODO(v9): Remove this warning
if (config?.vite?.build?.sourcemap === false) {
logger.warn(
"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.",
);
}

// TODO: Add deleteSourcemapsAfterUpload option and warn if it isn't set.

updateConfig({
vite: {
build: {
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export type IgnoreWarningsOption = (
// The two possible formats for providing custom webpack config in `next.config.js`
export type WebpackConfigFunction = (config: WebpackConfigObject, options: BuildContext) => WebpackConfigObject;
export type WebpackConfigObject = {
devtool?: string;
devtool?: string | boolean;
plugins?: Array<WebpackPluginInstance>;
entry: WebpackEntryProperty;
output: { filename: string; path: string };
Expand Down
24 changes: 22 additions & 2 deletions packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,33 @@ export function constructWebpackConfigFunction(

if (sentryWebpackPlugin) {
if (!userSentryOptions.sourcemaps?.disable) {
// TODO(v9): Remove this warning
if (newConfig.devtool === false) {
const runtimePrefix = !isServer ? 'Client' : runtime === 'edge' ? 'Edge' : 'Node.js';
// eslint-disable-next-line no-console
console.warn(
`[@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.`,
);
}

// TODO(v9): Remove this warning and print warning in case source map deletion is auto configured
if (!isServer && !userSentryOptions.sourcemaps?.deleteSourcemapsAfterUpload) {
// eslint-disable-next-line no-console
console.warn(
"[@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`.",
);
}

// `hidden-source-map` produces the same sourcemaps as `source-map`, but doesn't include the `sourceMappingURL`
// comment at the bottom. For folks who aren't publicly hosting their sourcemaps, this is helpful because then
// 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 || userNextConfig.productionBrowserSourceMaps ? 'source-map' : 'hidden-source-map';
if (isServer || userNextConfig.productionBrowserSourceMaps) {
newConfig.devtool = 'source-map';
} else {
newConfig.devtool = 'hidden-source-map';
}
}

newConfig.plugins = newConfig.plugins || [];
Expand Down
24 changes: 14 additions & 10 deletions packages/solidstart/src/vite/sourceMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ export function makeSourceMapsVitePlugin(options: SentrySolidStartPluginOptions)
apply: 'build',
enforce: 'post',
config(config) {
const sourceMapsPreviouslyNotEnabled = !config.build?.sourcemap;
if (debug && sourceMapsPreviouslyNotEnabled) {
// TODO(v9): Remove this warning
if (config.build?.sourcemap === false) {
// eslint-disable-next-line no-console
console.log('[Sentry SolidStart Plugin] Enabling source map generation');
if (!sourceMapsUploadOptions?.filesToDeleteAfterUpload) {
// eslint-disable-next-line no-console
console.warn(
`[Sentry SolidStart PLugin] We recommend setting the \`sourceMapsUploadOptions.filesToDeleteAfterUpload\` option to clean up source maps after uploading.
[Sentry SolidStart Plugin] Otherwise, source maps might be deployed to production, depending on your configuration`,
);
}
console.warn(
"[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.",
);
}

// TODO(v9): Remove this warning and print warning in case source map deletion is auto configured
if (!sourceMapsUploadOptions?.filesToDeleteAfterUpload) {
// eslint-disable-next-line no-console
console.warn(
"[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.",
);
}

return {
...config,
build: {
Expand Down

0 comments on commit 3fdab04

Please sign in to comment.