@@ -19,7 +19,10 @@ export { captureUnderscoreErrorException } from './utils/_error';
1919// because or SSR of next.js we can only use this.
2020export { ErrorBoundary , showReportDialog , withErrorBoundary } from '@sentry/react' ;
2121
22- type GlobalWithDistDir = typeof global & { __rewriteFramesDistDir__ : string } ;
22+ type GlobalWithBuildTimeConfiguration = typeof global & {
23+ __rewriteFramesDistDir__ : string ;
24+ __hasMiddleware__ : boolean ;
25+ } ;
2326const domain = domainModule as typeof domainModule & { active : ( domainModule . Domain & Carrier ) | null } ;
2427
2528// 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 {
104107
105108 // This value is injected at build time, based on the output directory specified in the build config. Though a default
106109 // 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' ;
108111 // nextjs always puts the build directory at the project root level, which is also where you run `next start` from, so
109112 // we can read in the project directory from the currently running process
110113 const distDirAbsPath = path . resolve ( process . cwd ( ) , distDirName ) ;
@@ -118,10 +121,12 @@ function addServerIntegrations(options: NextjsOptions): void {
118121 } ) ;
119122 integrations = addOrUpdateIntegration ( defaultRewriteFramesIntegration , integrations ) ;
120123
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+ }
125130
126131 if ( hasTracingEnabled ( options ) ) {
127132 const defaultHttpTracingIntegration = new Integrations . Http ( { tracing : true } ) ;
0 commit comments