mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
Closes PACK-5382
Previously, Turbopack validated every single module for route segment config, leading to false positives (on non-page files) and worse build performance. There were also three separate implementations of this logic.
Now, all of these cases are fatal errors, not just warnings.
Examples for errors
```
./bench/basic-app/app/export/inherit/page.tsx:1:28
Next.js can't recognize the exported `preferredRegion` field in route. It needs to be a static string or array of static strings.
> 1 | export { default, runtime, preferredRegion } from '../basic/foo'
| ^^^^^^^^^^^^^^^
The exported configuration object in a source file needs to have a very specific format from which some properties can be statically parsed at compiled-time.
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
```
This error message is slightly different now:
```
browser log: ./test/integration/app-dir-export/app/another/[slug]/page.js:6:8
Next.js can't recognize the exported `generateStaticParams` field in route. App pages cannot use both "use client" and export function "generateStaticParams()".
4 |
5 |
> 6 | export function generateStaticParams() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 7 | return [{ slug: 'first' }, { slug: 'second' }]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 8 | }
| ^^
9 |
10 | export default async function Page(props) {
11 | const params = await props.params
The exported configuration object in a source file needs to have a very specific format from which some properties can be statically parsed at compiled-time.
Import traces:
Client Component Browser:
./test/integration/app-dir-export/app/another/[slug]/page.js [Client Component Browser]
./test/integration/app-dir-export/app/another/[slug]/page.js [Server Component]
Client Component SSR:
./test/integration/app-dir-export/app/another/[slug]/page.js [Client Component SSR]
./test/integration/app-dir-export/app/another/[slug]/page.js [Server Component]
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
```
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { FileRef, nextTestSetup } from 'e2e-utils'
|
|
import path from 'path'
|
|
|
|
describe('app-dir edge SSR invalid reexport', () => {
|
|
const { next, isNextDev, skipped } = nextTestSetup({
|
|
files: {
|
|
'app/export': new FileRef(path.join(__dirname, 'app', 'export')),
|
|
'app/export/inherit/page.tsx':
|
|
"export { default, runtime, preferredRegion } from '../basic/page'",
|
|
},
|
|
skipStart: true,
|
|
skipDeployment: true,
|
|
})
|
|
|
|
if (skipped) {
|
|
return
|
|
}
|
|
|
|
it('should warn or error about the re-export of a pages runtime/preferredRegion config', async () => {
|
|
try {
|
|
await next.start()
|
|
} catch (_) {
|
|
// We expect the build to fail
|
|
}
|
|
|
|
if (isNextDev) {
|
|
const browser = await next.browser('/export/inherit')
|
|
// Turbopack is stricter and disallows reexports completely
|
|
// webpack merely warns in the CLI and still serves the page wuthout a redbox
|
|
if (process.env.IS_TURBOPACK_TEST) {
|
|
await expect(browser).toDisplayRedbox(`
|
|
{
|
|
"description": "Next.js can't recognize the exported \`preferredRegion\` field in route. It mustn't be reexported.",
|
|
"environmentLabel": null,
|
|
"label": "Build Error",
|
|
"source": "./app/export/inherit/page.tsx (1:28)
|
|
Next.js can't recognize the exported \`preferredRegion\` field in route. It mustn't be reexported.
|
|
> 1 | export { default, runtime, preferredRegion } from '../basic/page'
|
|
| ^^^^^^^^^^^^^^^",
|
|
"stack": [],
|
|
}
|
|
`)
|
|
}
|
|
}
|
|
|
|
expect(next.cliOutput).toInclude(
|
|
`Next.js can't recognize the exported \`runtime\` field in`
|
|
)
|
|
expect(next.cliOutput).toInclude(
|
|
`Next.js can't recognize the exported \`preferredRegion\` field in`
|
|
)
|
|
})
|
|
})
|