From fbaf37a5f67397dfd389a26dd3c6cef45e0388ed Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Sat, 7 Jan 2023 16:21:56 +0000 Subject: [PATCH] fix(nextjs): Don't write to `res.end` to fix `next export` --- packages/nextjs/src/config/wrappers/utils/responseEnd.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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); } }