Skip to content

Conversation

YukiKitagata
Copy link

Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

TL;DR

When use @sentry/nextjs with Next.js v12.0.9, Next.js server (next start) cannot process http request.

When you access the URL, the error in the image shows up and the server crashes.

image

$ next start
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
node:events:368
      throw er; // Unhandled 'error' event
      ^

TypeError: res.once is not a function
    at Domain.<anonymous> (node_modules/@sentry/nextjs/dist/utils/instrumentServer.js:170:33)
    at Domain.run (node:domain:378:15)
    at NextNodeServer.<anonymous> (node_modules/@sentry/nextjs/dist/utils/instrumentServer.js:148:23)
    at step (node_modules/tslib/tslib.js:141:27)
    at Object.next (node_modules/tslib/tslib.js:122:57)
    atnode_modules/tslib/tslib.js:115:75
    at new Promise (<anonymous>)

In this PR, we fixed this problem.

What is the cause of this error?

In Next.js v12.0.9, NextResponse was changed to NodeNextResponse.
With this change, NextResponse is no longer http.ServerResponse.

vercel/next.js@3e00a81#diff-96338e60ec87f8948c57d01f4d133a3afb9e09ad3e2af2856b0fc6841dc3d339R40

Measures

I created a function to get http.ServerResponse regardless of the Next.js version.

4688080#diff-0e65453e672d6580948eb593da1a572912d7393ba6c073dd107af0850b93c989R114-R127

@lobsterkatie
Copy link
Member

Hi, @YukiKitagata. Thanks for the PR!

There were a few small changes I needed to make to get it to work (you can see them here), but knowing what problem I was fixing going in was super helpful! I've credited you in that PR.

Cheers!

@YukiKitagata YukiKitagata deleted the fix/nextjs-12-0-9 branch June 20, 2022 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants