Skip to content

Commit 2227ae5

Browse files
authored
Revert "Fix: Throw an error for empty array return in generateStaticParams with output:export" (#60831)
Reverts #57053 per this comment: #57053 (comment) Instead of erroring, we should warn (and only in dev mode). That can be added in a future PR. Closes NEXT-2155
1 parent b7f5107 commit 2227ae5

File tree

5 files changed

+11
-45
lines changed

5 files changed

+11
-45
lines changed

packages/next/src/build/index.ts

+9-13
Original file line numberDiff line numberDiff line change
@@ -1887,19 +1887,15 @@ export default async function build(
18871887
const isDynamic = isDynamicRoute(page)
18881888
const hasGenerateStaticParams =
18891889
!!workerResult.prerenderRoutes?.length
1890-
const isEmptyGenerateStaticParams =
1891-
workerResult.prerenderRoutes?.length === 0
1892-
1893-
if (config.output === 'export' && isDynamic) {
1894-
if (isEmptyGenerateStaticParams) {
1895-
throw new Error(
1896-
`Page "${page}"'s "generateStaticParams()" returned an empty array, which is not allowed with "output: export" config.`
1897-
)
1898-
} else if (!hasGenerateStaticParams) {
1899-
throw new Error(
1900-
`Page "${page}" is missing "generateStaticParams()" so it cannot be used with "output: export" config.`
1901-
)
1902-
}
1890+
1891+
if (
1892+
config.output === 'export' &&
1893+
isDynamic &&
1894+
!hasGenerateStaticParams
1895+
) {
1896+
throw new Error(
1897+
`Page "${page}" is missing "generateStaticParams()" so it cannot be used with "output: export" config.`
1898+
)
19031899
}
19041900

19051901
if (

packages/next/src/server/base-server.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1797,12 +1797,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
17971797
)
17981798
}
17991799
const resolvedWithoutSlash = removeTrailingSlash(resolvedUrlPathname)
1800-
if (!staticPaths || staticPaths.length === 0) {
1801-
throw new Error(
1802-
`Page "${page}"'s "generateStaticParams()" returned an empty array, which is not allowed with "output: export" config.`
1803-
)
1804-
}
1805-
if (!staticPaths.includes(resolvedWithoutSlash)) {
1800+
if (!staticPaths?.includes(resolvedWithoutSlash)) {
18061801
throw new Error(
18071802
`Page "${page}" is missing param "${resolvedWithoutSlash}" in "generateStaticParams()", which is required with "output: export" config.`
18081803
)

test/integration/app-dir-export/test/dynamic-missing-gsp-dev.test.ts

-10
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,5 @@ describe('app dir - with output export - dynamic missing gsp dev', () => {
2121
'Page "/another/[slug]/page" cannot use both "use client" and export function "generateStaticParams()".',
2222
})
2323
})
24-
25-
it('should error when generateStaticParams returns an empty array', async () => {
26-
await runTests({
27-
isDev: true,
28-
dynamicPage: 'undefined',
29-
generateStaticParamsOpt: 'set empty',
30-
expectedErrMsg:
31-
'Page "/another/[slug]/page"\'s "generateStaticParams()" returned an empty array, which is not allowed with "output: export" config.',
32-
})
33-
})
3424
})
3525
})

test/integration/app-dir-export/test/dynamic-missing-gsp-prod.test.ts

-10
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,5 @@ describe('app dir - with output export - dynamic missing gsp prod', () => {
2121
'Page "/another/[slug]/page" cannot use both "use client" and export function "generateStaticParams()".',
2222
})
2323
})
24-
25-
it('should error when generateStaticParams returns an empty array', async () => {
26-
await runTests({
27-
isDev: false,
28-
dynamicPage: 'undefined',
29-
generateStaticParamsOpt: 'set empty',
30-
expectedErrMsg:
31-
'Page "/another/[slug]"\'s "generateStaticParams()" returned an empty array, which is not allowed with "output: export" config.',
32-
})
33-
})
3424
})
3525
})

test/integration/app-dir-export/test/utils.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export async function runTests({
9999
trailingSlash?: boolean
100100
dynamicPage?: string
101101
dynamicApiRoute?: string
102-
generateStaticParamsOpt?: 'set noop' | 'set client' | 'set empty'
102+
generateStaticParamsOpt?: 'set noop' | 'set client'
103103
expectedErrMsg?: string
104104
}) {
105105
if (trailingSlash !== undefined) {
@@ -124,11 +124,6 @@ export async function runTests({
124124
slugPage.replace('export function generateStaticParams', 'function noop')
125125
} else if (generateStaticParamsOpt === 'set client') {
126126
slugPage.prepend('"use client"\n')
127-
} else if (generateStaticParamsOpt === 'set empty') {
128-
slugPage.replace(
129-
"return [{ slug: 'first' }, { slug: 'second' }]",
130-
'return []'
131-
)
132127
}
133128
await fs.remove(distDir)
134129
await fs.remove(exportDir)

0 commit comments

Comments
 (0)