Skip to content

Commit 86ffdf4

Browse files
authored
fix(nextjs): Ignore tunnelRoute when doing static exports (#8471)
1 parent 97694e7 commit 86ffdf4

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

packages/nextjs/src/config/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export type NextConfigObject = {
4949
publicRuntimeConfig?: { [key: string]: unknown };
5050
// File extensions that count as pages in the `pages/` directory
5151
pageExtensions?: string[];
52+
// Whether Next.js should do a static export
53+
output?: string;
5254
// Paths to reroute when requested
5355
rewrites?: () => Promise<
5456
| NextRewrite[]

packages/nextjs/src/config/webpack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ function addValueInjectionLoader(
866866
const isomorphicValues = {
867867
// `rewritesTunnel` set by the user in Next.js config
868868
__sentryRewritesTunnelPath__:
869-
userSentryOptions.tunnelRoute !== undefined
869+
userSentryOptions.tunnelRoute !== undefined && userNextConfig.output !== 'export'
870870
? `${userNextConfig.basePath ?? ''}${userSentryOptions.tunnelRoute}`
871871
: undefined,
872872

packages/nextjs/src/config/withSentryConfig.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type {
88
} from './types';
99
import { constructWebpackConfigFunction } from './webpack';
1010

11+
let showedExportModeTunnelWarning = false;
12+
1113
/**
1214
* Add Sentry options to the config to be exported from the user's `next.config.js` file.
1315
*
@@ -48,7 +50,17 @@ function getFinalConfigObject(
4850
delete incomingUserNextConfigObject.sentry;
4951

5052
if (userSentryOptions?.tunnelRoute) {
51-
setUpTunnelRewriteRules(incomingUserNextConfigObject, userSentryOptions.tunnelRoute);
53+
if (incomingUserNextConfigObject.output === 'export') {
54+
if (!showedExportModeTunnelWarning) {
55+
showedExportModeTunnelWarning = true;
56+
// eslint-disable-next-line no-console
57+
console.warn(
58+
'[@sentry/nextjs] The Sentry Next.js SDK `tunnelRoute` option will not work in combination with Next.js static exports. The `tunnelRoute` option uses serverside features that cannot be accessed in export mode. If you still want to tunnel Sentry events, set up your own tunnel: https://docs.sentry.io/platforms/javascript/troubleshooting/#using-the-tunnel-option',
59+
);
60+
}
61+
} else {
62+
setUpTunnelRewriteRules(incomingUserNextConfigObject, userSentryOptions.tunnelRoute);
63+
}
5264
}
5365

5466
return {

0 commit comments

Comments
 (0)