Skip to content

Commit 9f89eae

Browse files
authored
feat(nextjs): Add transpileClientSDK option and build config page (#5350)
In getsentry/sentry-javascript#5472, a `transpileClientSDK` option was added to the nextjs SDK to force SDK code to be transpiled along with other app code, primarily for the use of folks wanting to use the SDK in older browsers without support for ES6 or ES6+ features like object spread. This documents that option by: - Adding a section to the manual setup page (which is where other build-time options live) - Adding a new 'Build Options' page redirecting people to the relevant section of of the manual setup page, for greater discoverability - Adding a nextjs-specific include to a new legacy browser support section on the Troubleshooting page. (A generic include has also been added for the non-nextjs JS docs, detailing how to do manually what the added option causes the nextjs SDK to do automatically.)
1 parent bee1f41 commit 9f89eae

File tree

5 files changed

+125
-2
lines changed

5 files changed

+125
-2
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
For example, if you're using Webpack and Babel, and you have the following code in your `webpack.config.js`, you'll want to modify `exclude` so it doesn't block the SDK.
2+
3+
Before:
4+
5+
```javascript {filename:webpack.config.js}
6+
module: {
7+
rules: [
8+
{
9+
test: /\.(js)$/,
10+
exclude: /node_modules/,
11+
use: ['babel-loader']
12+
}
13+
]
14+
},
15+
```
16+
17+
After:
18+
19+
```javascript {filename:webpack.config.js}
20+
module: {
21+
rules: [
22+
{
23+
test: /\.(js)$/,
24+
// Make sure to include all `@sentry` packages, not just the main SDK package
25+
exclude: filepath => filepath.includes("node_modules") && !filepath.includes("@sentry"),
26+
use: ['babel-loader']
27+
}
28+
]
29+
},
30+
```
31+
32+
Though the above example is Webpack-specific, similar changes can be made to configuraton for Rollup, esbuild, and the like.
33+
34+
<PlatformSection notSupported={[
35+
"javascript.angular",
36+
"javascript.capacitor",
37+
"javascript.cordova",
38+
"javascript.electron",
39+
"javascript.ember",
40+
"javascript.gatsby",
41+
"javascript.nextjs",
42+
"javascript.react",
43+
"javascript.remix",
44+
"javascript.vue",
45+
"javascript.wasm",
46+
]}>
47+
48+
As an alternative, you can use one of our ES5-specific <PlatformLink to="/install/cdn/#available-bundles">CDN bundles</PlatformLink>.
49+
50+
</PlatformSection>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
In order to do this, set the `sentry.transpileClientSDK` option in your `next.config.js`:
2+
3+
```javascript {filename:next.config.js}
4+
const { withSentryConfig } = require("@sentry/nextjs");
5+
6+
const moduleExports = {
7+
// < other nextjs config >
8+
9+
sentry: {
10+
transpileClientSDK: true,
11+
},
12+
};
13+
14+
const sentryWebpackPluginOptions = {
15+
// < webpack plugin config >
16+
};
17+
18+
module.exports = withSentryConfig(moduleExports, sentryWebpackPluginOptions);
19+
```
20+
21+
For more information, please see [Extend Next.js Configuration](../manual-setup/#extend-nextjs-configuration).

src/platforms/javascript/common/troubleshooting/index.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ To fix this, change the `tracingOrigins` option during SDK initialization. For m
7070

7171
## `instrument.js` Line Numbers for Console Log statements
7272

73-
If `instrument.js` displays in your console while debugging, add Sentry to your [Framework Ignore List](https://developer.chrome.com/docs/devtools/javascript/ignore-chrome-extension-scripts/) by adding this pattern: `/@sentry/`
73+
If `instrument.js` displays in your console while debugging, add Sentry to your [Framework Ignore List](https://developer.chrome.com/docs/devtools/javascript/ignore-chrome-extension-scripts/) by adding this pattern: `/@sentry/`
7474

7575
Chrome then ignores the SDK stack frames when debugging.
7676

@@ -421,3 +421,9 @@ document.body.addEventListener(
421421
```
422422

423423
Remember to pass in `true` as the second parameter to `addEventListener()`. Without it, the event handler won't be called, since it's being added to the event target's ancestor rather than the event target itself, and unlike JavaScript runtime errors, `error` events resulting from load failures don't bubble, and therefore must be captured during the `capture` phase. For more information, see [the W3C spec](https://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/events.html#Events-phases).
424+
425+
## Supporting Older Browsers
426+
427+
Starting with version 7.0.0, the Sentry JavaScript SDK uses ES6 syntax, along with a few other ES6+ language features, like object spread. If you are down-compiling your code in order to target older browsers that don't support such syntax, you'll need to include the Sentry SDK in that process.
428+
429+
<PlatformContent includePath="troubleshooting/older-browser-support" />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Build Options
3+
sidebar_order: 5
4+
description: "Learn about configuration options used in `next.config.js` to control your app's build process."
5+
keywords:
6+
[
7+
"next.js",
8+
"nextjs",
9+
"next.config",
10+
"sourcemaps",
11+
"source maps",
12+
"build",
13+
"compatibility",
14+
"ES6",
15+
"ES5",
16+
]
17+
---
18+
19+
The Sentry Next.js SDK supports automatic code injection and source map upload during your app's build process using the `withSentryConfig` wrapper in `next.config.js`. For information on the available configuration options, see [Extend Next.js Configuration](../../manual-setup/#extend-nextjs-configuration).

src/platforms/javascript/guides/nextjs/manual-setup.mdx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sidebar_order: 1
44
description: "Learn how to set up the SDK manually."
55
---
66

7-
If you cant (or prefer not to) run the [configuration step](/platforms/javascript/guides/nextjs/#configure), you can follow the instructions below to configure your application.
7+
If you can't (or prefer not to) run the [configuration step](/platforms/javascript/guides/nextjs/#configure), you can follow the instructions below to configure your application.
88

99
## Create Initialization Config Files
1010

@@ -161,6 +161,17 @@ const { withSentryConfig } = require("@sentry/nextjs");
161161

162162
const moduleExports = {
163163
// your existing module.exports
164+
165+
// Optional build-time configuration options
166+
sentry: {
167+
// See the 'Configure Source Maps' and 'Configure Legacy Browser Support'
168+
// sections below for information on the following options:
169+
// - disableServerWebpackPlugin
170+
// - disableClientWebpackPlugin
171+
// - hideSourceMaps
172+
// - widenClientFileUpload
173+
// - transpileClientSDK
174+
},
164175
};
165176

166177
const sentryWebpackPluginOptions = {
@@ -287,3 +298,19 @@ Alternatively, the cli can be configured using environment variables.
287298
| `defaults.org` | `SENTRY_ORG` |
288299
| `defaults.project` | `SENTRY_PROJECT` |
289300
| `auth.token` | `SENTRY_AUTH_TOKEN` |
301+
302+
## Configure Legacy Browser Support
303+
304+
_(New in version 7.8.0)_
305+
306+
The `@sentry/nextjs` SDK is designed to run in browsers which support ES6 (and certain ES6+ language features like object spread). If you need to support older browsers, and have configured Next.js to down-compile your code, you can apply the same down-compilation to the injected SDK code by using the `transpileClientSDK` option in your `next.config.js`:
307+
308+
```javascript {filename:next.config.js}
309+
const moduleExports = {
310+
sentry: {
311+
transpileClientSDK: true,
312+
},
313+
};
314+
```
315+
316+
(This assumes you are using [the `next.config.js` setup shown above](#extend-nextjs-configuration).)

0 commit comments

Comments
 (0)