From 6aef15dc23df594e8d7f4ea6141c1cbbfe257431 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 27 Jan 2022 16:31:54 -0600 Subject: [PATCH] Ensure non-error thrown in getStaticPaths shows correctly (#33753) --- packages/next/build/index.ts | 2 +- .../test/index.test.js | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index e55eafd73d1d13b..c10e46307b8b894 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -1028,7 +1028,7 @@ export default async function build( ) } } catch (err) { - if (isError(err) && err.message !== 'INVALID_DEFAULT_EXPORT') + if (!isError(err) || err.message !== 'INVALID_DEFAULT_EXPORT') throw err invalidPages.add(page) } 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 912d82569b02375..bf12b6ded2989c8 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 @@ -1,5 +1,6 @@ /* eslint-env jest */ +import fs from 'fs-extra' import path from 'path' import { nextBuild } from 'next-test-utils' @@ -15,4 +16,43 @@ describe('Invalid Page automatic static optimization', () => { expect(stderr).toMatch(/pages\/invalid/) expect(stderr).toMatch(/pages\/also-invalid/) }) + + it('handles non-error correctly', async () => { + const testPage = path.join(appDir, 'pages/[slug].js') + await fs.rename(path.join(appDir, 'pages'), path.join(appDir, 'pages-bak')) + + await fs.ensureDir(path.join(appDir, 'pages')) + await fs.writeFile( + testPage, + ` + export default function Page() { + return

hello world

+ } + + export function getStaticPaths() { + throw 'invalid API token' + } + + export function getStaticProps() { + return { + props: { + hello: 'world' + } + } + } + ` + ) + + try { + const { stderr } = await nextBuild(appDir, [], { stderr: true }) + expect(stderr).toMatch(/invalid API token/) + expect(stderr).not.toMatch(/without a React Component/) + } finally { + await fs.remove(path.join(appDir, 'pages')) + await fs.rename( + path.join(appDir, 'pages-bak'), + path.join(appDir, 'pages') + ) + } + }) })