From 53ab3104e0de1bba329ff60da1bc03e5be7db6a4 Mon Sep 17 00:00:00 2001 From: Sarah Mischinger Date: Thu, 20 Feb 2025 13:52:39 +0100 Subject: [PATCH 1/3] move capture error content --- .../javascript/guides/nextjs/manual-setup.mdx | 53 ++----------------- .../capture-error/javascript.nextjs.mdx | 50 +++++++++++++++++ 2 files changed, 53 insertions(+), 50 deletions(-) diff --git a/docs/platforms/javascript/guides/nextjs/manual-setup.mdx b/docs/platforms/javascript/guides/nextjs/manual-setup.mdx index f7ef7a32be748..e6ccb816f6855 100644 --- a/docs/platforms/javascript/guides/nextjs/manual-setup.mdx +++ b/docs/platforms/javascript/guides/nextjs/manual-setup.mdx @@ -67,13 +67,14 @@ export default withSentryConfig(nextConfig, { ``` ### Extend Sentry Webpack Plugin Options + `withSentryConfig` uses a [custom Webpack plugin](https://www.npmjs.com/package/@sentry/webpack-plugin) to manage your sourcemaps and releases under the hood. If `withSentryConfig` does not provide the option you need to modify, you may override the `sentryWebpackPluginOptions` directly via `unstable_sentryWebpackPluginOptions`. - Note that this option is unstable and its API may include breaking changes in any release. + Note that this option is unstable and its API may include breaking changes in + any release. - ## Create Initialization Config Files Create three files in the root directory of your Next.js application: `sentry.client.config.js`, `sentry.server.config.js` and `sentry.edge.config.js`. In these files, add your initialization code for the client-side SDK and server-side SDK, respectively. We've included some examples below. @@ -175,7 +176,6 @@ export async function register() { } ``` - Make sure that the `import` statements point to your newly created `sentry.server.config.(js|ts)` and `sentry.edge.config.(js|ts)` files. ## Report React Component Render Errors @@ -239,53 +239,6 @@ export default function GlobalError({ error }) { } ``` -Note that if you create [Next.js error.js files](https://nextjs.org/docs/app/building-your-application/routing/error-handling), these files will take precedence over the `global-error.js` file. -This means, that if you want to report errors that are caught by `error.js` files, you need to manually capture them: - -```tsx {filename:error.tsx} -"use client"; - -import { useEffect } from "react"; -import * as Sentry from "@sentry/nextjs"; - -export default function ErrorPage({ - error, -}: { - error: Error & { digest?: string }; -}) { - useEffect(() => { - // Log the error to Sentry - Sentry.captureException(error); - }, [error]); - - return ( -
-

Something went wrong!

-
- ); -} -``` - -```jsx {filename:error.jsx} -"use client"; - -import { useEffect } from "react"; -import * as Sentry from "@sentry/nextjs"; - -export default function ErrorPage({ error }) { - useEffect(() => { - // Log the error to Sentry - Sentry.captureException(error); - }, [error]); - - return ( -
-

Something went wrong!

-
- ); -} -``` - #### Errors from Nested React Server Components _Requires `@sentry/nextjs` version `8.28.0` or higher and Next.js 15._ diff --git a/platform-includes/capture-error/javascript.nextjs.mdx b/platform-includes/capture-error/javascript.nextjs.mdx index bd719fc8f9266..8355748c73cb8 100644 --- a/platform-includes/capture-error/javascript.nextjs.mdx +++ b/platform-includes/capture-error/javascript.nextjs.mdx @@ -9,3 +9,53 @@ try { Sentry.captureException(err); } ``` + + +Note that if you create [Next.js `error.js` files](https://nextjs.org/docs/app/building-your-application/routing/error-handling), these files will take precedence over any global error handling. +This means, that if you want to report errors that are caught by `error.js` files, you need to manually capture them: + +```tsx {filename:error.tsx} +"use client"; + +import { useEffect } from "react"; +import * as Sentry from "@sentry/nextjs"; + +export default function ErrorPage({ + error, +}: { + error: Error & { digest?: string }; +}) { + useEffect(() => { + // Log the error to Sentry + Sentry.captureException(error); + }, [error]); + + return ( +
+

Something went wrong!

+
+ ); +} +``` + +```jsx {filename:error.jsx} +"use client"; + +import { useEffect } from "react"; +import * as Sentry from "@sentry/nextjs"; + +export default function ErrorPage({ error }) { + useEffect(() => { + // Log the error to Sentry + Sentry.captureException(error); + }, [error]); + + return ( +
+

Something went wrong!

+
+ ); +} +``` + +
From 4b61f4c8718d931d0b21ec9343c03d38bcb700b9 Mon Sep 17 00:00:00 2001 From: Sarah Mischinger Date: Thu, 20 Feb 2025 13:57:21 +0100 Subject: [PATCH 2/3] adapt formatting --- platform-includes/capture-error/javascript.nextjs.mdx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/platform-includes/capture-error/javascript.nextjs.mdx b/platform-includes/capture-error/javascript.nextjs.mdx index 8355748c73cb8..f974e092fc212 100644 --- a/platform-includes/capture-error/javascript.nextjs.mdx +++ b/platform-includes/capture-error/javascript.nextjs.mdx @@ -10,7 +10,8 @@ try { } ``` - +### Capturing Errors in `error.js` Files + Note that if you create [Next.js `error.js` files](https://nextjs.org/docs/app/building-your-application/routing/error-handling), these files will take precedence over any global error handling. This means, that if you want to report errors that are caught by `error.js` files, you need to manually capture them: @@ -57,5 +58,3 @@ export default function ErrorPage({ error }) { ); } ``` - - From e4c9f46b1d292af8d4c508f388e8e9d0809c21ec Mon Sep 17 00:00:00 2001 From: Sarah Mischinger Date: Wed, 26 Feb 2025 16:43:14 +0100 Subject: [PATCH 3/3] formatting fix Co-authored-by: Charly Gomez --- platform-includes/capture-error/javascript.nextjs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-includes/capture-error/javascript.nextjs.mdx b/platform-includes/capture-error/javascript.nextjs.mdx index f974e092fc212..b262d0650a90d 100644 --- a/platform-includes/capture-error/javascript.nextjs.mdx +++ b/platform-includes/capture-error/javascript.nextjs.mdx @@ -12,7 +12,7 @@ try { ### Capturing Errors in `error.js` Files -Note that if you create [Next.js `error.js` files](https://nextjs.org/docs/app/building-your-application/routing/error-handling), these files will take precedence over any global error handling. +Note that if you create [Next.js error.js files](https://nextjs.org/docs/app/building-your-application/routing/error-handling), these files will take precedence over any global error handling. This means, that if you want to report errors that are caught by `error.js` files, you need to manually capture them: ```tsx {filename:error.tsx}