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

Next.js tries to generate static 500 even with getInitialProps in _app.js #23568

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

Comments

@laSinteZ
Copy link

laSinteZ commented Mar 31, 2021

What version of Next.js are you using?

10.1.2

What version of Node.js are you using?

v15.6.0

What browser are you using?

Chrome

What operating system are you using?

macOS 11.1 (M1)

How are you deploying your application?

next build

Describe the Bug

When I try to build an application, it fails on [= ] info - Generating static pages (0/1), because next.js tries to build static 500 page, even though getInitialProps is present in _app.js

➜  repro-500 git:(main) ✗ npm run build

> repro-500@0.1.0 build /Users/vyacheslavbikbaev/Projects/repro-500
> next build

info  - Using webpack 4. Reason: future.webpack5 option not enabled https://nextjs.org/docs/messages/webpack5
info  - Checking validity of types  
info  - Creating an optimized production build  
info  - Compiled successfully
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://nextjs.org/docs/messages/opt-out-auto-static-optimization

info  - Collecting page data  
[=   ] info  - Generating static pages (0/1)
Error occurred prerendering page "/500". Read more: https://nextjs.org/docs/messages/prerender-error
FetchError: request to http://127.0.0.1/some-backend-url failed, reason: connect ECONNREFUSED 127.0.0.1:80
    at ClientRequest.<anonymous> (/Users/vyacheslavbikbaev/Projects/repro-500/node_modules/node-fetch/lib/index.js:1461:11)
    at ClientRequest.emit (events.js:314:20)
    at Socket.socketErrorListener (_http_client.js:427:9)
    at Socket.emit (events.js:314:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
info  - Generating static pages (1/1)

> Build error occurred
Error: Export encountered errors on following paths:
        /500
    at /Users/vyacheslavbikbaev/Projects/repro-500/node_modules/next/dist/export/index.js:31:1106
    at async Span.traceAsyncFn (/Users/vyacheslavbikbaev/Projects/repro-500/node_modules/next/dist/telemetry/trace/trace.js:5:584)
    at async /Users/vyacheslavbikbaev/Projects/repro-500/node_modules/next/dist/build/index.js:43:49
    at async Span.traceAsyncFn (/Users/vyacheslavbikbaev/Projects/repro-500/node_modules/next/dist/telemetry/trace/trace.js:5:584)
    at async /Users/vyacheslavbikbaev/Projects/repro-500/node_modules/next/dist/build/index.js:25:1475
    at async Span.traceAsyncFn (/Users/vyacheslavbikbaev/Projects/repro-500/node_modules/next/dist/telemetry/trace/trace.js:5:584)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! repro-500@0.1.0 build: `next build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the repro-500@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/vyacheslavbikbaev/.npm/_logs/2021-03-31T07_46_30_214Z-debug.log

Expected Behavior

500 error should not be statically generated in case getInitialProps is present in _app (since it is said to opt out whole app from ASO).

To Reproduce

https://github.com/laSinteZ/nextjs-10-1-error-500 (npm install, then npm run build)

Notice that creating custom _error.js page with getInitialProps helps (since 500 isn't statically generated in that case I guess).

@laSinteZ laSinteZ added the bug Issue was opened via the bug report template. label Mar 31, 2021
@rashidul0405
Copy link
Contributor

reporting the same error. And I guess I shouldn't force to use to add /500 if I don't want to? @Timer @timneutkens

@rashidul0405
Copy link
Contributor

sort of duplicate of #23128

@laSinteZ
Copy link
Author

Very true, looks like duplicate, didn't see #23128, well I have a repro repo here :)
@rashidul0405 I agree that we shouldn't be forced to add /500, since getInitialProps in _app is told to opt-out from static generation (in docs). Also, custom /500 won't help, you need custom _error.

@laSinteZ
Copy link
Author

laSinteZ commented Apr 2, 2021

According to tests, this is an intended behaviour:

it('still builds 500 statically with getInitialProps in _app', async () => {

Why is it different from 404 though :(

@rmsheppard
Copy link

I'm having issues with this as well. Seems to me like having the getInitialProps in _app should disable all static loading. I'm not sure why this needs to happen or if there is a way to turn if off.

@laSinteZ
Copy link
Author

laSinteZ commented Apr 7, 2021

@rmsheppard a way to turn it off is to create a custom _error file with getInitialProps in it. According to tests, it will disable it. (and it helped me in my project).

it('does not build 500 statically with no pages/500 and custom getInitialProps in _error', async () => {

@rutaboo
Copy link

rutaboo commented Apr 9, 2021

This seems to be a breaking change from previous version, I've upgraded and ended up with this issue as well as others.

@ijjk
Copy link
Member

ijjk commented Apr 17, 2021

Closing as a duplicate of #23128

@ijjk ijjk closed this as completed Apr 17, 2021
@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

6 participants