diff --git a/errors/page-without-valid-component.md b/errors/page-without-valid-component.md index 31f7e7f464837..9344b712c9dbb 100644 --- a/errors/page-without-valid-component.md +++ b/errors/page-without-valid-component.md @@ -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. diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index a7bd15cbdb757..d6c88ef87df26 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -411,7 +411,7 @@ export default async function build(dir: string, conf = null): Promise { 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}`) diff --git a/test/integration/invalid-page-automatic-static-optimization/test/index.test.js b/test/integration/invalid-page-automatic-static-optimization/test/index.test.js index bcecd517ef7e7..847172a9a707a 100644 --- a/test/integration/invalid-page-automatic-static-optimization/test/index.test.js +++ b/test/integration/invalid-page-automatic-static-optimization/test/index.test.js @@ -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/)