Skip to content

Next 10.0.8 attempts to generate static error pages despite _error with getInitialProps #22815

@merrywhether

Description

@merrywhether

What version of Next.js are you using?

10.0.8

What version of Node.js are you using?

12.13.0

What browser are you using?

All

What operating system are you using?

macOS

How are you deploying your application?

Own infra

Describe the Bug

We have an _error component with getInitialProps (as does our _app component) and no /404 or /500 components, as we need dynamism on these routes for i18n, tracking, etc. Under 10.0.7, this correctly opted all error paths out of static optimization during build:

Warning: You have opted-out of Automatic Static Optimization due to `getInitialProps` in `pages/_app`. This does not opt-out pages with `getStaticProps`
Read more: https://err.sh/next.js/opt-out-auto-static-optimization

info  - Collecting page data  
Page                                           Size     First Load JS
┌ λ /                                          306 B           429 kB
├   /_app                                      0 B             296 kB
├ λ /404                                       308 B           429 kB
├ λ /login                                     309 B           429 kB
├ λ /not-found                                 309 B           429 kB
...etc

Under 10.0.8, next build attempts to erroneously generate static pages, which fails because they rely on dynamism (specifically data collected from our custom server and transported into Next via the req object):

Warning: You have opted-out of Automatic Static Optimization due to `getInitialProps` in `pages/_app`. This does not opt-out pages with `getStaticProps`
Read more: https://err.sh/next.js/opt-out-auto-static-optimization

info  - Collecting page data  
[  ==] info  - Generating static pages (0/3)
Error occurred prerendering page "/404". Read more: https://err.sh/next.js/prerender-error
...

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

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

info  - Generating static pages (3/3)

> Build error occurred
Error: Export encountered errors on following paths:
	/404
	/404.html
	/500

I'm guessing this was introduced alongside the new static /500 component introduction?

Expected Behavior

next build won't attempt to generate static pages for 404/500 paths when _error has getInitialProps defined and no static 404 or 500 components are defined

To Reproduce

Attempt to build a next app with _error with getInitialProps defined and no 500 or 404 components

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions