Skip to content

Commit 4ce3845

Browse files
author
Luca Forstner
authored
feat(nextjs): Emit warning if your app directory doesn't have a global-error.js file (#9753)
1 parent a848c5a commit 4ce3845

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ let showedMissingOrgSlugErrorMsg = false;
4040
let showedMissingProjectSlugErrorMsg = false;
4141
let showedHiddenSourceMapsWarningMsg = false;
4242
let showedMissingCliBinaryWarningMsg = false;
43+
let showedMissingGlobalErrorWarningMsg = false;
4344

4445
// TODO: merge default SentryWebpackPlugin ignore with their SentryWebpackPlugin ignore or ignoreFile
4546
// TODO: merge default SentryWebpackPlugin include with their SentryWebpackPlugin include
@@ -328,6 +329,24 @@ export function constructWebpackConfigFunction(
328329
});
329330
}
330331

332+
if (appDirPath) {
333+
const hasGlobalErrorFile = ['global-error.js', 'global-error.jsx', 'global-error.ts', 'global-error.tsx'].some(
334+
globalErrorFile => fs.existsSync(path.join(appDirPath!, globalErrorFile)),
335+
);
336+
337+
if (!hasGlobalErrorFile && !showedMissingGlobalErrorWarningMsg) {
338+
// eslint-disable-next-line no-console
339+
console.log(
340+
`${chalk.yellow(
341+
'warn',
342+
)} - It seems like you don't have a global error handler set up. It is recommended that you add a ${chalk.cyan(
343+
'global-error.js',
344+
)} 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`,
345+
);
346+
showedMissingGlobalErrorWarningMsg = true;
347+
}
348+
}
349+
331350
// The SDK uses syntax (ES6 and ES6+ features like object spread) which isn't supported by older browsers. For users
332351
// who want to support such browsers, `transpileClientSDK` allows them to force the SDK code to go through the same
333352
// transpilation that their code goes through. We don't turn this on by default because it increases bundle size

0 commit comments

Comments
 (0)