@sentry/nextjs: withSentry with webpack 5 crashes server with ERR_STREAM_WRITE_AFTER_END
- [ ] Review the documentation: https://docs.sentry.io/
- [ ] Search for existing issues: https://github.com/getsentry/sentry-javascript/issues
- [ ] Use the latest release: https://github.com/getsentry/sentry-javascript/releases
- [ ] Provide a link to the affected event from your Sentry account
Package + Version
- [x]
@sentry/nextjs @ 6.5.0 - [x]
next @ 10.2.3
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.js
const nextConfig = {
future: {
webpack5: true
}
};
module.exports = withSentryConfig(nextConfig, sentryWebpackOpts);
// pages/api/hello.ts
import type { NextApiRequest, NextApiResponse } from 'next'
import { withSentry } from '@sentry/nextjs';
export default withSentry((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
Same setup and same issue. Thanks for reporting the temporary workaround -> downgrading to @sentry/nextjs @ 6.4.1 worked for me
same issue here
this move to @sentry/nextjs has been pretty nightmare-ish - y'all really should remove it from the official nextjs example as it's riddled with bugs and workarounds with very little documentation. Not a happy customer.
Same issue here, just upgraded to 6.5.0, and it brought down our site. All NextJS API Routes started returning 500 errors with no Sentry logs / alerts, ERR_STREAM_WRITE_AFTER_END
Hey, sorry about that, we are working on a fix for this as we speak.
6.5.1 should unblock you all, we are working on a fix that resolves this.
This should be fully resolved with https://github.com/getsentry/sentry-javascript/pull/3811. Please open another GH issue if there are further problems.