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

Remove static optimization from message #9045

Merged
merged 3 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions errors/page-without-valid-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

#### Why This Error Occurred

While auto exporting a page a valid React Component wasn't found. This could mean you have a file in `pages` that exports something that is not a React Component.
A page that does not export a valid React Component was found while analyzing the build output.

This is a hard error because the page would error when rendered, and causes poor build performance.

#### Possible Ways to Fix It

Move any non-page files that don't export a React Component as the default export to a different folder like `components` or `lib`.
Investigate the list of page(s) specified in the error message.
For each, you'll want to check if the file is meant to be a page.

If the file is not meant to be a page, and instead, is a shared component or file, move the file to a different folder like `components` or `lib`.

If the file is meant to be a page, double check you have an `export default` with the React Component instead of an `export`. If you're already using `export default`, make sure the returned valid is a valid React Component.
2 changes: 1 addition & 1 deletion packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export default async function build(dir: string, conf = null): Promise<void> {

if (invalidPages.size > 0) {
throw new Error(
`automatic static optimization failed: found page${
`Build optimization failed: found page${
invalidPages.size === 1 ? '' : 's'
} without a React Component as default export in \n${[...invalidPages]
.map(pg => `pages${pg}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Invalid Page automatic static optimization', () => {
const { stderr } = await nextBuild(appDir, [], { stderr: true })

expect(stderr).toMatch(
/automatic static optimization failed: found pages without a React Component as default export in/
/Build optimization failed: found pages without a React Component as default export in/
)
expect(stderr).toMatch(/pages\/invalid/)
expect(stderr).toMatch(/pages\/also-invalid/)
Expand Down