@@ -19,7 +19,10 @@ export { captureUnderscoreErrorException } from './utils/_error';
19
19
// because or SSR of next.js we can only use this.
20
20
export { ErrorBoundary , showReportDialog , withErrorBoundary } from '@sentry/react' ;
21
21
22
- type GlobalWithDistDir = typeof global & { __rewriteFramesDistDir__ : string } ;
22
+ type GlobalWithBuildTimeConfiguration = typeof global & {
23
+ __rewriteFramesDistDir__ : string ;
24
+ __hasMiddleware__ : boolean ;
25
+ } ;
23
26
const domain = domainModule as typeof domainModule & { active : ( domainModule . Domain & Carrier ) | null } ;
24
27
25
28
// Exporting this constant means we can compute it without the linter complaining, even if we stop directly using it in
@@ -104,7 +107,7 @@ function addServerIntegrations(options: NextjsOptions): void {
104
107
105
108
// This value is injected at build time, based on the output directory specified in the build config. Though a default
106
109
// is set there, we set it here as well, just in case something has gone wrong with the injection.
107
- const distDirName = ( global as GlobalWithDistDir ) . __rewriteFramesDistDir__ || '.next' ;
110
+ const distDirName = ( global as GlobalWithBuildTimeConfiguration ) . __rewriteFramesDistDir__ || '.next' ;
108
111
// nextjs always puts the build directory at the project root level, which is also where you run `next start` from, so
109
112
// we can read in the project directory from the currently running process
110
113
const distDirAbsPath = path . resolve ( process . cwd ( ) , distDirName ) ;
@@ -118,10 +121,12 @@ function addServerIntegrations(options: NextjsOptions): void {
118
121
} ) ;
119
122
integrations = addOrUpdateIntegration ( defaultRewriteFramesIntegration , integrations ) ;
120
123
121
- const nativeBehaviourOnUncaughtException = new Integrations . OnUncaughtException ( ) ;
122
- integrations = addOrUpdateIntegration ( nativeBehaviourOnUncaughtException , integrations , {
123
- _options : { exitEvenIfOtherHandlersAreRegistered : false } ,
124
- } ) ;
124
+ if ( ( global as GlobalWithBuildTimeConfiguration ) . __hasMiddleware__ ) {
125
+ const nativeBehaviourOnUncaughtException = new Integrations . OnUncaughtException ( ) ;
126
+ integrations = addOrUpdateIntegration ( nativeBehaviourOnUncaughtException , integrations , {
127
+ _options : { exitEvenIfOtherHandlersAreRegistered : false } ,
128
+ } ) ;
129
+ }
125
130
126
131
if ( hasTracingEnabled ( options ) ) {
127
132
const defaultHttpTracingIntegration = new Integrations . Http ( { tracing : true } ) ;
0 commit comments