From 6c1b4bd71b463cbecc30144bd0931f96ec87da2d Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Wed, 2 Jun 2021 12:29:32 -0400 Subject: [PATCH] fix(nextjs): Prevent webpack 5 from crashing server (#3642) It seems that awaiting a flush() call is throwing errors in Webpack 5. This crashes the server as the handler has already sent a response at that point. This patch wraps the flush call in a try, catch until we can figure out a better fix. --- packages/nextjs/src/utils/handlers.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/nextjs/src/utils/handlers.ts b/packages/nextjs/src/utils/handlers.ts index c8b61f08fded..ecb5103c6db6 100644 --- a/packages/nextjs/src/utils/handlers.ts +++ b/packages/nextjs/src/utils/handlers.ts @@ -81,7 +81,11 @@ export const withSentry = (handler: NextApiHandler): WrappedNextApiHandler => { transaction.finish(); } - await flush(2000); + try { + await flush(2000); + } catch (e) { + // no-empty + } } }; };