From 40bc176792942f2a2ed29632edc84a3328734a92 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Fri, 11 Oct 2019 09:52:30 -0400 Subject: [PATCH 1/2] Remove static optimization from message This check does not pertain to automatic static optimization. Closes https://github.com/zeit/next.js/issues/9042 --- packages/next/build/index.ts | 2 +- .../test/index.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/) From 6cd8f743ed9e32aa5d04209047e6d5ec55f91d8e Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Fri, 11 Oct 2019 10:02:54 -0400 Subject: [PATCH 2/2] Update help message --- errors/page-without-valid-component.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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.