diff --git a/packages/nextjs/src/config/wrappers/utils/responseEnd.ts b/packages/nextjs/src/config/wrappers/utils/responseEnd.ts index 21d5f5d850a5..82b6fb69ea28 100644 --- a/packages/nextjs/src/config/wrappers/utils/responseEnd.ts +++ b/packages/nextjs/src/config/wrappers/utils/responseEnd.ts @@ -31,7 +31,8 @@ export function autoEndTransactionOnResponseEnd(transaction: Transaction, res: S }; // Prevent double-wrapping - if (!(res.end as WrappedResponseEndMethod).__sentry_original__) { + // res.end may be undefined during build when using `next export` to statically export a Next.js app + if (res.end && !(res.end as WrappedResponseEndMethod).__sentry_original__) { fill(res, 'end', wrapEndMethod); } }