Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/nextjs/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export type NextConfigObject = {
publicRuntimeConfig?: { [key: string]: unknown };
// File extensions that count as pages in the `pages/` directory
pageExtensions?: string[];
// Whether Next.js should do a static export
output?: string;
// Paths to reroute when requested
rewrites?: () => Promise<
| NextRewrite[]
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ function addValueInjectionLoader(
const isomorphicValues = {
// `rewritesTunnel` set by the user in Next.js config
__sentryRewritesTunnelPath__:
userSentryOptions.tunnelRoute !== undefined
userSentryOptions.tunnelRoute !== undefined && userNextConfig.output !== 'export'
? `${userNextConfig.basePath ?? ''}${userSentryOptions.tunnelRoute}`
: undefined,

Expand Down
14 changes: 13 additions & 1 deletion packages/nextjs/src/config/withSentryConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import type {
} from './types';
import { constructWebpackConfigFunction } from './webpack';

let showedExportModeTunnelWarning = false;

/**
* Add Sentry options to the config to be exported from the user's `next.config.js` file.
*
Expand Down Expand Up @@ -48,7 +50,17 @@ function getFinalConfigObject(
delete incomingUserNextConfigObject.sentry;

if (userSentryOptions?.tunnelRoute) {
setUpTunnelRewriteRules(incomingUserNextConfigObject, userSentryOptions.tunnelRoute);
if (incomingUserNextConfigObject.output === 'export') {
if (!showedExportModeTunnelWarning) {
showedExportModeTunnelWarning = true;
// eslint-disable-next-line no-console
console.warn(
'[@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',
);
}
} else {
setUpTunnelRewriteRules(incomingUserNextConfigObject, userSentryOptions.tunnelRoute);
}
}

return {
Expand Down