Closed
Description
- 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
-
@sentry/nextjs @ 6.5.0
-
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