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

Build error when opt-out static optimatization and providing custom Error page #22907

Closed
piotrrussw opened this issue Mar 9, 2021 · 5 comments
Labels
bug Issue was opened via the bug report template.

Comments

@piotrrussw
Copy link

piotrrussw commented Mar 9, 2021

What version of Next.js are you using?

10.0.8

What version of Node.js are you using?

14.x.x

What browser are you using?

What operating system are you using?

linux

How are you deploying your application?

other

Describe the Bug

After upgrading to next.js 10.0.8 I can't build my application. I get the following error:

Error occurred prerendering page "/404". Read more: https://err.sh/next.js/prerender-error
TypeError: res.writeHead is not a function

I have opt-out static optimatization in _app.js and provide custom _error.js page.
The following error throws during build process and affects pages: /404, /404.html, /500
I think it might be connected with #22139

Expected Behavior

To be able to build page

To Reproduce

You can try same configuration as in sandbox

Not sure if it is a bug or it requires docs update.

Best,
Piotr

@piotrrussw piotrrussw added the bug Issue was opened via the bug report template. label Mar 9, 2021
@lipoolock
Copy link

More or less same issue on my side

I extracted content of ctx below, diplayed just before the error occurs

[  ==] info  - Generating static pages (0/7)headers {
  err: undefined,
  req: {
    url: '/500',
    headers: {},
    getHeader: [Function: getHeader],
    setHeader: [Function: setHeader],
    hasHeader: [Function: hasHeader],
    removeHeader: [Function: removeHeader],
    getHeaderNames: [Function: getHeaderNames]
  },
  res: {
    headers: {},
    getHeader: [Function: getHeader],
    setHeader: [Function: setHeader],
    hasHeader: [Function: hasHeader],
    removeHeader: [Function: removeHeader],
    getHeaderNames: [Function: getHeaderNames]
  },
  pathname: '/_error',
  query: {},
  asPath: '/500',
  AppTree: [Function: AppTree]
}

Error occurred prerendering page "/de/500". Read more: https://err.sh/next.js/prerender-error

I do not expect having any URL like /de/500 on my application, so I don't understand why NextJs is trying to pre-render this...

@lipoolock
Copy link

lipoolock commented Mar 9, 2021

On my application, this error occurs on build step. This step pass through a getInitialProps in a custom _app file.
This is a required config for me.

The issue documented above concerns the fact that my application is expecting to receive some data in ctx.headers and ctx.res but has displayed in the payload, headers is empty and res does not contain writeHead for instance

To solve this I have been forced to return an error status at the beginning of _app.js if the expected data are missing.

I would be happy to understand why I'm forced to do that now and if there is a way to deactivate 500/400 prerendering

@ijjk
Copy link
Member

ijjk commented Mar 9, 2021

Hi, this looks like a duplicate of #22815 which is fixed in v10.0.9-canary.3, please update and give it a try!

@ijjk ijjk closed this as completed Mar 9, 2021
@lipoolock
Copy link

Hi @ijjk
Thanks a lot, you are right, that solves the issue and that was a duplicate for me 👍

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

4 participants