Unverified Commit b72dc5b6 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Improve the error message when custom export fields are used in an entry (#42221)

parent fc397caa
# Invalid Layout or Page Export
#### Why This Error Occurred
Your [layout](https://beta.nextjs.org/docs/api-reference/file-conventions/layout) or [page](https://beta.nextjs.org/docs/api-reference/file-conventions/page) inside the app directory exports an invalid field. In these files, you're only allowed to export a default React component, or [Segment Configuration Options](https://beta.nextjs.org/docs/api-reference/segment-config) for layout and pages, such as `revalidate`, `generateStaticParams`, etc.
Other custom exports are not allowed to catch misspelt configuration options and prevent conflicts with future options.
#### Possible Ways to Fix It
You can create a new file and co-locate it with the page or layout. In the new file, you can export any custom fields and import it from anywhere.
...@@ -753,6 +753,10 @@ ...@@ -753,6 +753,10 @@
{ {
"title": "google-fonts-missing-subsets", "title": "google-fonts-missing-subsets",
"path": "/errors/google-fonts-missing-subsets.md" "path": "/errors/google-fonts-missing-subsets.md"
},
{
"title": "invalid-segment-export",
"path": "/errors/invalid-segment-export.md"
} }
] ]
} }
......
...@@ -116,9 +116,9 @@ function getFormattedLayoutAndPageDiagnosticMessageText( ...@@ -116,9 +116,9 @@ function getFormattedLayoutAndPageDiagnosticMessageText(
if (filepathAndInvalidExport) { if (filepathAndInvalidExport) {
const main = `${type} "${chalk.bold( const main = `${type} "${chalk.bold(
relativeSourceFile relativeSourceFile
)}" exports invalid field "${chalk.bold( )}" exports an invalid "${chalk.bold(
filepathAndInvalidExport[2] filepathAndInvalidExport[2]
)}". Only "default" and other configuration exports are allowed.` )}" field. ${type} should only export a default React component and configuration options. Learn more: https://nextjs.org/docs/messages/invalid-segment-export`
return main return main
} }
break break
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment