Skip to content

Commit

Permalink
fix(nextjs): Ignore tunnelRoute when doing static exports (#8471)
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed Jul 7, 2023
1 parent 97694e7 commit 86ffdf4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
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

0 comments on commit 86ffdf4

Please sign in to comment.