From caa9927522d9b35d4f82f35e6e37ba83f7ed5dd8 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 5 Jun 2024 09:24:54 +0000 Subject: [PATCH] feat(nextjs): Allow for suppressing warning about missing global error handler file Fixes https://github.com/getsentry/sentry-javascript/issues/12367 --- packages/nextjs/src/config/webpack.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 44537ede59f8..e529a2b47f57 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -291,14 +291,18 @@ export function constructWebpackConfigFunction( globalErrorFile => fs.existsSync(path.join(appDirPath!, globalErrorFile)), ); - if (!hasGlobalErrorFile && !showedMissingGlobalErrorWarningMsg) { + if ( + !hasGlobalErrorFile && + !showedMissingGlobalErrorWarningMsg && + !process.env.SENTRY_SUPPRESS_GLOBAL_ERROR_HANDLER_FILE_WARNING + ) { // eslint-disable-next-line no-console console.log( `${chalk.yellow( 'warn', )} - It seems like you don't have a global error handler set up. It is recommended that you add a ${chalk.cyan( 'global-error.js', - )} file with Sentry instrumentation so that React rendering errors are reported to Sentry. Read more: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#react-render-errors-in-app-router`, + )} file with Sentry instrumentation so that React rendering errors are reported to Sentry. Read more: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#react-render-errors-in-app-router (you can suppress this warning by setting SENTRY_SUPPRESS_GLOBAL_ERROR_HANDLER_FILE_WARNING=1 as environment variable)`, ); showedMissingGlobalErrorWarningMsg = true; }