The Wayback Machine - http://web.archive.org/web/20220328074453/https://github.com/vercel/next.js/issues/34025
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

Inaccurate error message when getStaticProps exported from page without a page component #34025

Open

Merlin04 opened this issue Feb 6, 2022 · 1 comment · May be fixed by #34287
Open

Inaccurate error message when getStaticProps exported from page without a page component #34025

Merlin04 opened this issue Feb 6, 2022 · 1 comment · May be fixed by #34287
Labels
area: Developer Experience area: Static Generation good first issue

Comments

@Merlin04
Copy link

@Merlin04 Merlin04 commented Feb 6, 2022

Run next info (available from version 12.0.8 and up)

/bin/sh: 1: pnpm: not found

    Operating System:
      Platform: linux
      Arch: x64
      Version: #109-Ubuntu SMP Wed Jan 12 16:49:16 UTC 2022
    Binaries:
      Node: 16.13.2
      npm: 8.1.2
      Yarn: 1.22.5
      pnpm: N/A
    Relevant packages:
      next: 12.0.11-canary.6
      react: 17.0.2
      react-dom: 17.0.2

What version of Next.js are you using?

12.0.11-canary.6

What version of Node.js are you using?

16.13.2

What browser are you using?

Firefox

What operating system are you using?

Ubuntu

How are you deploying your application?

next dev

Describe the Bug

When you have a page file which has a getStaticProps function exported, but no default export for a page component:

export const getStaticProps = async (context) => ({
    redirect: {
        destination: "https://example.com",
        permanent: false
    }
});

You get this server error:

Error: page /pageName getStaticProps can not be attached to a page's component and must be exported from the page. See more info here: https://nextjs.org/docs/messages/gssp-component-member

Even though the getStaticProps is correctly exported from the page.

Expected Behavior

Ideally having no page component export would be allowed and not cause an error (it's useful in cases where you'd only ever return a redirect or an error), but if this isn't supported the error message should say something like

Error: page /pageName does not have a default export page component. If the page won't ever render, export a function that returns null.

To Reproduce

  1. Create a page that has a getStaticProps function but no default page component export, like the example in the "describe the bug" section
  2. Run next dev
  3. Navigate to the page in your browser
@Merlin04 Merlin04 added the template: bug label Feb 6, 2022
@balazsorban44 balazsorban44 added area: Static Generation area: Developer Experience good first issue and removed template: bug labels Feb 6, 2022
@keshav-bohr
Copy link

@keshav-bohr keshav-bohr commented Feb 7, 2022

Hi @Merlin04

In the docs, it is mentioned that the page has to be created with export default.
https://nextjs.org/learn/basics/navigate-between-pages/pages-in-nextjs

Don't know why they haven't mentioned it in the main docs. But this is the recommended behaviour, i guess.

@stmtk1 stmtk1 linked a pull request that will close this issue Feb 13, 2022

8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Developer Experience area: Static Generation good first issue
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants