You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(nextjs): Add option to have TS sentry config files, other small fixes (#3960)
This documents the change in getsentry/sentry-javascript#3847, which allows for TypeScript versions of `sentry.server.config.js` and `sentry.client.config.js`, by adding TypeScript versions of those files to the code blocks.
It also includes a few other small fixes:
- Also add a Typescript version of the `withSentry` code snippet, both on the manual setup page and the getting started page.
- Move the alert about not supporting the `serverless` target into the section about `next.config.js`, which is where it's relevant.
- Remove the split between the snippet for `sentry.server.config.js` and `sentry.client.config.js`, as they were the exact same code. Instead, both filenames are listed on the snippet.
- Add filenames to the two `next.config.js` snippets which were missing them.
- Let the autoformatter do its thing.
Copy file name to clipboardExpand all lines: src/includes/getting-started-config/javascript.nextjs.mdx
+15-5
Original file line number
Diff line number
Diff line change
@@ -18,13 +18,23 @@ Once you're set up, the SDK will automatically capture unhandled errors and prom
18
18
19
19
To capture [Next.js API Route](https://nextjs.org/docs/api-routes/introduction) errors and monitor server performance, you need to wrap your handlers with a Sentry function:
20
20
21
-
```javascript
22
-
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
Copy file name to clipboardExpand all lines: src/platforms/javascript/guides/nextjs/manual-setup.mdx
+23-13
Original file line number
Diff line number
Diff line change
@@ -10,9 +10,9 @@ If you can’t (or prefer not to) run the [configuration step](/platforms/javasc
10
10
11
11
Create two files in the root directory of your project, `sentry.client.config.js` and `sentry.server.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.
If you want to instrument [Next.js API Routes](https://nextjs.org/docs/api-routes/introduction), which run on serverless, you need to wrap your handler in our `withSentry` wrapper in order to be able to capture crashes:
`@sentry/nextjs` does not support configurations with the `serverless` target. To use the SDK in serverless environments, switch to using the `experimental-serverless-trace` target, which is [recommended by the Next.js maintainers](https://github.com/vercel/next.js/issues/20487#issuecomment-753884085).
70
+
exportdefaultwithSentry(handler);
71
+
```
68
72
69
-
</Alert>
73
+
You can include your DSN directly in these two files, or provide it in either of two environment variables, `SENTRY_DSN` or `NEXT_PUBLIC_SENTRY_DSN`.
`@sentry/nextjs` does not support configurations with the `serverless` target. To use the SDK in serverless environments, switch to using the `experimental-serverless-trace` target, which is [recommended by the Next.js maintainers](https://github.com/vercel/next.js/issues/20487#issuecomment-753884085).
116
+
117
+
</Alert>
118
+
109
119
Make sure to add the Sentry config last; otherwise, the source maps the plugin receives may not be final.
110
120
111
121
## Configure Source Maps
@@ -116,7 +126,7 @@ To configure the plugin, pass a `SentryWebpackPluginOptions` argument to `withSe
116
126
117
127
If you want or need to handle source map uploading separately, the plugin can be disabled for either the server or client build process. To do this, add a `sentry` object to `moduleExports` above, and set the relevant options there:
118
128
119
-
```javascript
129
+
```javascript {filename:next.config.js}
120
130
constmoduleExports= {
121
131
sentry: {
122
132
disableServerWebpackPlugin:true,
@@ -127,7 +137,7 @@ const moduleExports = {
127
137
128
138
If you disable the plugin for both server and client builds, it's safe to omit the `SentryWebpackPluginOptions` parameter from your `withSentryConfig` call:
0 commit comments