#Page does not match the required types of a Next.js Page. "X" is not a valid Page export field.

11 messages · Page 1 of 1 (latest)

rustic vapor
#

page.tsx is exporting:

  1. X named export for Zod Type to be used in other files.
  2. The actual page as the default. But I am getting the error in the title.

Page "src/../page.tsx" does not match the required types of a Next.js Page. "X" is not a valid Page export field.

export const X = z.object({});

export default function MyPage() {
}

Am I not allowed to have named exports in page.tsx files? Its odd because only this single page is giving me an issue. I have named exports in other page.tsx files and no issue.

raw gustBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

      🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in <id:customize>

      ✅ You can mark a message as the answer for your post with `Right click -> Apps -> Mark Solution`
      (if you don't see the option, try refreshing Discord with Ctrl + R)
inland rune
#

Am I not allowed to have named exports in page.tsx files?
I don't think so. the pages now have a lot of named exports so they are probably trying to avoid mistakes like a typo in an exported method

rustic vapor
#

Yeah, I'm not sure what to do. This is only happening on one of my pages.

This is my named export, if you are curiousPaymentMethodSchema, but if I remove that it just complains about my other named exports defaultPaymentMethods which is just an array of type PaymentMethods.

inland rune
#

you shouldn't be exporting anything besides what Next.js expects from pages. if you do this then I believe you are importing the page files in other pages, which is definately not a good idea since it will mess up the bundle

#

you can move these exports to a separate file that can be imported by multiple pages

rustic vapor
inland rune
#

why do you need to export them tho?

rustic vapor
#

Other pages use the types and schema. For basic CRUD operations. I have my schema + types in the index page (all users). The create user page and user ID page need the types

inland rune
#

ah yeah you can't do that, you need to move the schemas to another file to share them

rustic vapor
#

thanks, this is solved then