8000 fix(nextjs): Show errors and warnings only once during build (#7651) · ileonovdima/sentry-javascript@3a91a62 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3a91a62

Browse files
authored
fix(nextjs): Show errors and warnings only once during build (getsentry#7651)
1 parent 8a25d00 commit 3a91a62

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ const RUNTIME_TO_SDK_ENTRYPOINT_MAP = {
2828
edge: './edge',
2929
} as const;
3030

31+
// Next.js runs webpack 3 times, once for the client, the server, and for edge. Because we don't want to print certain
32+
// warnings 3 times, we keep track of them here.
33+
let showedMissingAuthTokenErrorMsg = false;
34+
let showedMissingOrgSlugErrorMsg = false;
35+
let showedMissingProjectSlugErrorMsg = false;
36+
let showedHiddenSourceMapsWarningMsg = false;
37+
3138
// TODO: merge default SentryWebpackPlugin ignore with their SentryWebpackPlugin ignore or ignoreFile
3239
// TODO: merge default SentryWebpackPlugin include with their SentryWebpackPlugin include
3340
// TODO: drop merged keys from override check? `includeDefaults` option?
@@ -649,12 +656,15 @@ export function getWebpackPluginOptions(
649656
)} environment variable during the build.`;
650657
}
651658

652-
// eslint-disable-next-line no-console
653-
console.error(
654-
`${errorMessagePrefix} ${chalk.bold(
655-
'No Sentry auth token configured.',
656-
)} Source maps will not be uploaded.\n${msg}\n`,
657-
);
659+
if (!showedMissingAuthTokenErrorMsg) {
660+
// eslint-disable-next-line no-console
661+
console.error(
662+
`${errorMessagePrefix} ${chalk.bold(
663+
'No Sentry auth token configured.',
664+
)} Source maps will not be uploaded.\n${msg}\n`,
665+
);
666+
showedMissingAuthTokenErrorMsg = true;
667+
}
658668

659669
return;
660670
}
@@ -672,12 +682,15 @@ export function getWebpackPluginOptions(
672682
)} environment variable to the to your organization slug during the build.`;
673683
}
674684

675-
// eslint-disable-next-line no-console
676-
console.error(
677-
`${errorMessagePrefix} ${chalk.bold(
678-
'No Sentry organization slug configured.',
679-
)} Source maps will not be uploaded.\n${msg}\n`,
680-
);
685+
if (!showedMissingOrgSlugErrorMsg) {
686+
// eslint-disable-next-line no-console
687+
console.error(
688+
`${errorMessagePrefix} ${chalk.bold(
689+
'No Sentry organization slug configured.',
690+
)} Source maps will not be uploaded.\n${msg}\n`,
691+
);
692+
showedMissingOrgSlugErrorMsg = true;
693+
}
681694

682695
return;
683696
}
@@ -695,12 +708,15 @@ export function getWebpackPluginOptions(
695708
)} environment variable to the name of your Sentry project during the build.`;
696709
}
697710

698-
// eslint-disable-next-line no-console
699-
console.error(
700-
`${errorMessagePrefix} ${chalk.bold(
701-
'No Sentry project slug configured.',
702-
)} Source maps will not be uploaded.\n${msg}\n`,
703-
);
711+
if (!showedMissingProjectSlugErrorMsg) {
712+
// eslint-disable-next-line no-console
713+
console.error(
714+
`${errorMessagePrefix} ${chalk.bold(
715+
'No Sentry project slug configured.',
716+
)} Source maps will not be uploaded.\n${msg}\n`,
717+
);
718+
showedMissingProjectSlugErrorMsg = true;
719+
}
704720

705721
return;
706722
}
@@ -775,7 +791,7 @@ function handleSourcemapHidingOptionWarning(userSentryOptions: UserSentryOptions
775791
const _sentry_ = codeFormat('sentry');
776792
const _nextConfigJS_ = codeFormat('next.config.js');
777793

778-
if (isServer && userSentryOptions.hideSourceMaps === undefined) {
794+
if (isServer && userSentryOptions.hideSourceMaps === undefined && !showedHiddenSourceMapsWarningMsg) {
779795
// eslint-disable-next-line no-console
780796
console.warn(
781797
`\n${_warningPrefix_} In order to be able to deminify errors, ${_sentryNextjs_} creates sourcemaps and uploads ` +
@@ -787,6 +803,7 @@ function handleSourcemapHidingOptionWarning(userSentryOptions: UserSentry 5D48 Options
787803
'https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#use-hidden-source-map for more ' +
788804
'information.\n',
789805
);
806+
showedHiddenSourceMapsWarningMsg = true;
790807
}
791808

792809
// TODO (v8): Remove the check above in favor of the one below

0 commit comments

Comments
 (0)
0