Skip to content

Commit 6aef15d

Browse files
authored
Ensure non-error thrown in getStaticPaths shows correctly (#33753)
1 parent 7ec49be commit 6aef15d

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

packages/next/build/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ export default async function build(
10281028
)
10291029
}
10301030
} catch (err) {
1031-
if (isError(err) && err.message !== 'INVALID_DEFAULT_EXPORT')
1031+
if (!isError(err) || err.message !== 'INVALID_DEFAULT_EXPORT')
10321032
throw err
10331033
invalidPages.add(page)
10341034
}

test/integration/invalid-page-automatic-static-optimization/test/index.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-env jest */
22

3+
import fs from 'fs-extra'
34
import path from 'path'
45
import { nextBuild } from 'next-test-utils'
56

@@ -15,4 +16,43 @@ describe('Invalid Page automatic static optimization', () => {
1516
expect(stderr).toMatch(/pages\/invalid/)
1617
expect(stderr).toMatch(/pages\/also-invalid/)
1718
})
19+
20+
it('handles non-error correctly', async () => {
21+
const testPage = path.join(appDir, 'pages/[slug].js')
22+
await fs.rename(path.join(appDir, 'pages'), path.join(appDir, 'pages-bak'))
23+
24+
await fs.ensureDir(path.join(appDir, 'pages'))
25+
await fs.writeFile(
26+
testPage,
27+
`
28+
export default function Page() {
29+
return <p>hello world</p>
30+
}
31+
32+
export function getStaticPaths() {
33+
throw 'invalid API token'
34+
}
35+
36+
export function getStaticProps() {
37+
return {
38+
props: {
39+
hello: 'world'
40+
}
41+
}
42+
}
43+
`
44+
)
45+
46+
try {
47+
const { stderr } = await nextBuild(appDir, [], { stderr: true })
48+
expect(stderr).toMatch(/invalid API token/)
49+
expect(stderr).not.toMatch(/without a React Component/)
50+
} finally {
51+
await fs.remove(path.join(appDir, 'pages'))
52+
await fs.rename(
53+
path.join(appDir, 'pages-bak'),
54+
path.join(appDir, 'pages')
55+
)
56+
}
57+
})
1858
})

0 commit comments

Comments
 (0)