Page does not match the required types of a Next.js Page. "X" is not a valid Page export field.
Answered
Grass carp posted this in #help-forum
Grass carpOP
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.Answered by Rafael Almeida
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
9 Replies
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
Answer
Grass carpOP
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 curious
This is my named export, if you are curious
PaymentMethodSchema, but if I remove that it just complains about my other named exports defaultPaymentMethods which is just an array of type PaymentMethods.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
@Rafael Almeida 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
Grass carpOP
Yeah I like to keep my Zod Schema and TS types with the actual page as easier to hold a mental model. Very odd
why do you need to export them tho?
Grass carpOP
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
ah yeah you can't do that, you need to move the schemas to another file to share them
Grass carpOP
thanks, this is solved then