vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.86k stars 26.97k forks source link

pages/_error breaks on vercel when using getInitialProps #37418

Closed LonJonn closed 1 year ago

LonJonn commented 2 years ago

Verify canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:24 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T8101
Binaries:
  Node: 16.13.1
  npm: 8.1.2
  Yarn: 3.2.1
  pnpm: N/A
Relevant packages:
  next: 12.1.7-canary.29
  react: 18.1.0
  react-dom: 18.1.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

Using getInitialProps within pages/_error causes Vercel serverless functions to crash and not display the _error component. This doesn't happen locally when using next build && next start, but only when deployed to Vercel.

image

This issue seems to have been brought up last year but nothing has been done about it.

Creating a 500.tsx page prevents the ugly crash page from displaying, but then the _error.tsx page isn't executing, losing the ability to do server-side error logging e.g. with sentry.

I've also noticed that exporting getServerSideProps within _error seems to work locally but breaks the same way as getInitialProps in production. Not sure what this means re: this issue, but I thought I'd mention it as well.

Expected Behavior

getInitialProps should execute and the custom _error page should be server rendered and displayed.

To Reproduce

This bug occurs with the most basic create-next-app setup + following this section of the official docs. It even happens with the with-sentry example (I literally just hit the vercel deploy button in the README.md and it broke, see https://nextjs-sentry-example-one.vercel.app/)

Literally clone and deploy the with-sentry example.

ytw0728 commented 2 years ago

Was the sample app broken on '/ssr/test3' or '/ssr/test4'? If so, I think it would be related to "unhandled rejection" option of node 15 or later.

In my case, the process was killed by unhandled rejection caused in getServerSideProps.

LonJonn commented 2 years ago

I posted a preview deployment of the sample app and both /ssr/test3 and /ssr/test4 are broken. Regardless of config, the fact that the official with-sentry example breaks using the deploy on Vercel button means something is wrong.

ytw0728 commented 2 years ago

Oh, yeah. There are some error throwing during build time. (pages/api/test1.js, pages/api/test2.js)

We have to fix them first to build the sample app.

Although after fixing them, however, the sample app is broken on '/ssr/test3' and '/ssr/test4'.

jankaifer commented 1 year ago

repro: https://github.com/JanKaifer/next-repro-37418.git deployed: https://37418.vercel.app/

It works now.

github-actions[bot] commented 1 year ago

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.