fix(DX): More precise error messages for export const config deprecation (#54492)

Before:
```
Error: `export const config` in /vercel/path0/src/app/api/route.js is deprecated. Please change `runtime` property to segment export config. See https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
```

After:
```
Error: `export const config` in /vercel/path0/src/app/api/route.js is deprecated:
  - Change `config.runtime…` to `export const runtime = "edge"`
  - Change `config.regions…` to `export const preferredRegion = ["us-east-1"]`
Visit https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config for more information.
```

The values proposed in Change.. are the actual ones from the customers, they can just copy paste.

Closes NEXT-1560
This commit is contained in:
Vincent Voyer 2023-08-25 18:25:15 +02:00 committed by GitHub
parent 41be932238
commit e4ff4da7c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 3 deletions

View file

@ -527,7 +527,22 @@ export async function getPageStaticInfo(params: {
if (pageType === 'app') {
if (config) {
const message = `\`export const config\` in ${pageFilePath} is deprecated. Please change \`runtime\` property to segment export config. See https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config`
let message = `Page config in ${pageFilePath} is deprecated. Replace \`export const config=…\` with the following:`
if (config.runtime) {
message += `\n - \`export const runtime = ${JSON.stringify(
config.runtime
)}\``
}
if (config.regions) {
message += `\n - \`export const preferredRegion = ${JSON.stringify(
config.regions
)}\``
}
message += `\nVisit https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config for more information.`
if (isDev) {
Log.warnOnce(message)
} else {

View file

@ -9,4 +9,5 @@ export default function Page() {
export const config = {
runtime: 'edge',
regions: ['us-east-1'],
}

View file

@ -19,9 +19,15 @@ createNextDescribe(
} else {
expect(error).toBeDefined()
}
expect(next.cliOutput).toContain('`export const config`')
expect(next.cliOutput).toContain('Page config in ')
expect(next.cliOutput).toContain(
'app/legacy-runtime-config/page.js is deprecated. Please change `runtime` property to segment export config. See https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config'
// the full path is more complex, we only care about this part
'app/legacy-runtime-config/page.js is deprecated. Replace `export const config=…` with the following:'
)
expect(next.cliOutput).toContain('- `export const runtime = "edge"`')
expect(next.cliOutput).toContain(
'- `export const preferredRegion = ["us-east-1"]`'
)
})
}