Package + Version
Description
When using @sentry/nextjs with webpack 5, calling any API function wrapped in withSentry will crash the server.
Error [ERR_STREAM_WRITE_AFTER_END]: write after end
// next.config.jsconstnextConfig={future: {webpack5: true}};module.exports=withSentryConfig(nextConfig,sentryWebpackOpts);// pages/api/hello.tsimporttype{NextApiRequest,NextApiResponse}from'next'import{withSentry}from'@sentry/nextjs';exportdefaultwithSentry((req: NextApiRequest,res: NextApiResponse)=>{res.status(200).json({name: 'John Doe'})});After a while debugging, the withSentry function seems to throw an error (well, it throws the value false) after the API function returns. This causes Nextjs to send a 500 error response, however because the function has already sent a response, this causes an uncaught ERR_STREAM_WRITE_AFTER_END error, crashing the server.
Workarounds
- Downgrade to @sentry/nextjs @ 6.4.1
- Use webpack 4
- Remove withSentry uses
Package + Version
@sentry/nextjs @ 6.5.0next @ 10.2.3Description
When using
@sentry/nextjswith webpack 5, calling any API function wrapped inwithSentrywill crash the server.After a while debugging, the
withSentryfunction seems to throw an error (well, it throws the valuefalse) after the API function returns. This causes Nextjs to send a 500 error response, however because the function has already sent a response, this causes an uncaughtERR_STREAM_WRITE_AFTER_ENDerror, crashing the server.Workarounds