Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@sentry/nextjs: withSentry with webpack 5 crashes server with ERR_STREAM_WRITE_AFTER_END #3636

Closed
2 of 6 tasks
AsherFoster opened this issue Jun 2, 2021 · 7 comments · Fixed by #3811
Closed
2 of 6 tasks
Assignees
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug

Comments

@AsherFoster
Copy link

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
@joneath
Copy link

joneath commented Jun 2, 2021

Same setup and same issue. Thanks for reporting the temporary workaround -> downgrading to @sentry/nextjs @ 6.4.1 worked for me

@AbhiPrasad AbhiPrasad added Package: nextjs Issues related to the Sentry Nextjs SDK Status: Confirmed Type: Bug and removed Status: Needs Triage labels Jun 2, 2021
@AbhiPrasad AbhiPrasad self-assigned this Jun 2, 2021
@aidan-ayala
Copy link

same issue here

@lcdproductions
Copy link

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.

@nickfreeman
Copy link

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

@HazAT
Copy link
Member

HazAT commented Jun 2, 2021

Hey, sorry about that, we are working on a fix for this as we speak.

@HazAT
Copy link
Member

HazAT commented Jun 2, 2021

6.5.1 should unblock you all, we are working on a fix that resolves this.

@AbhiPrasad
Copy link
Member

AbhiPrasad commented Jul 14, 2021

This should be fully resolved with #3811. Please open another GH issue if there are further problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants