Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from
Aug 25, 2023
17 changes: 16 additions & 1 deletion packages/next/src/build/analysis/get-page-static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `\`export const config\` in ${pageFilePath} is deprecated:`
vvo marked this conversation as resolved.
Show resolved Hide resolved

if (config.runtime) {
message += `\n - Change \`config.runtime…\` to \`export const runtime = ${JSON.stringify(
vvo marked this conversation as resolved.
Show resolved Hide resolved
config.runtime
)}\``
}

if (config.regions) {
message += `\n - Change \`config.regions…\` to \`export const preferredRegion = ${JSON.stringify(
vvo marked this conversation as resolved.
Show resolved Hide resolved
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export default function Page() {

export const config = {
runtime: 'edge',
regions: ['us-east-1'],
}
11 changes: 9 additions & 2 deletions test/e2e/app-dir-legacy-edge-runtime-config/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ createNextDescribe(
} else {
expect(error).toBeDefined()
}
expect(next.cliOutput).toContain('`export const config`')
expect(next.cliOutput).toContain('`export const 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'
)
expect(next.cliOutput).toContain(
'- Change `config.runtime…` to `export const runtime = "edge"'
)
expect(next.cliOutput).toContain(
'- Change `config.regions…` to `export const preferredRegion = ["us-east-1"]`'
)
})
}
Expand Down