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

pages/404 can not have getInitialProps/getServerSideProps #10919

Closed
ebidel opened this issue Mar 10, 2020 · 4 comments · Fixed by #10974
Closed

pages/404 can not have getInitialProps/getServerSideProps #10919

ebidel opened this issue Mar 10, 2020 · 4 comments · Fixed by #10974
Milestone

Comments

@ebidel
Copy link
Contributor

ebidel commented Mar 10, 2020

Bug report

Describe the bug

A custom pages/404.tsx:

import React from 'react';
export default = () => <h1>This is the 404 page</h1>;

causes an internal server error on the dev server. The log error complains about getInitialProps;
note: we have a custom _app.tsx file that uses getInitialProps.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. create the 404 page above
  2. create a custom _app that uses getInitialProps.

Expected behavior

No error or suggests using _error.js. Note: using a _error.js works for us.

Screenshots

Screen Shot 2020-03-09 at 10 07 27 PM

System information

  • OS: [e.g. macOS, Windows] macos
  • Browser (if applies) [e.g. chrome, safari] chrome
  • Version of Next.js: 9.3.0
@ssig33
Copy link

ssig33 commented Mar 10, 2020

I have a similar problem.

if pages/[id].js is following

export default ()=> <h1>something...</h1> 

For example, we can access the following URL:

  • /1
  • /2
  • /hogehoge
  • /404

but, /404 can not be generated on next build

@chiqui3d
Copy link

chiqui3d commented Mar 10, 2020

Same problem here:

Example:

404.js

import Head from "next/head";
import HeaderTop from "../components/Header/HeaderTop";
import HeaderMainWithBackground from "../components/Header/HeaderMainWithBackground";
import S404 from "../components/Sections/S404";
import Footer from "../components/Sections/Footer";


export default (props) => {
    return (
        <>
            <Head>
                <title>{props.t('Error.title')}</title>
                <meta name="description" content={props.t('Error.description')} />
            </Head>
            <HeaderTop/>
            <HeaderMainWithBackground background="asdasd.jpg" pageName={props.t('Error.name')} {...props}/>
            <S404 {...props}/>
            <Footer {...props}/>
        </>
    )
};

@ijjk
Copy link
Member

ijjk commented Mar 11, 2020

Hi, it looks like the `pages/404` can not have getInitialProps/getServerSideProps, https://err.sh/zeit/next.js/404-get-initial-props error was being shown incorrectly in development which should be addressed in #10974.

Note: having getInitialProps in _app does prevent the 404 page from being statically optimized and you are strictly not allowed to use getInitialProps or getServerSideProps in pages/404 even if you do use getInitialProps in _app

@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 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants