@sentry/nextjs: withSentry with webpack 5 crashes server with ERR_STREAM_WRITE_AFTER_END
See original GitHub issue- 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
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Getting ERR_STREAM_WRITE_AFTER_END after #4139
Generally, the Next.js sentry module works very well, but after 6.14.3, I experienced crashes on any request in prod:.
Read more >Can not run server after add sentry to nextjs project
The solution to this problem is, upgrade next.js to >= 10.0.8 github.com/getsentry/sentry-javascript/issues/3724.
Read more >Build fails after adding Sentry to a Next.js app with target
After adding Sentry to a Next.js app with target: 'serverless' using npx @sentry/wizard -i nextjs , I get the following error:
Read more >@sentry/nextjs Webpack 5 code duplication bug - Giters
I have the same issue with @sentry/nextjs . It started happening with Next.js 10.2.1 where Sokra added some Webpack optimizations.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.