From e4ff4da7c8ac7f25f08c7764fba0d1daf59c56cc Mon Sep 17 00:00:00 2001 From: Vincent Voyer Date: Fri, 25 Aug 2023 18:25:15 +0200 Subject: [PATCH] fix(DX): More precise error messages for export const config deprecation (#54492) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../src/build/analysis/get-page-static-info.ts | 17 ++++++++++++++++- .../app/legacy-runtime-config/page.js | 1 + .../index.test.ts | 10 ++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/next/src/build/analysis/get-page-static-info.ts b/packages/next/src/build/analysis/get-page-static-info.ts index 9951b583b1..6d6cc421f8 100644 --- a/packages/next/src/build/analysis/get-page-static-info.ts +++ b/packages/next/src/build/analysis/get-page-static-info.ts @@ -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 { diff --git a/test/e2e/app-dir-legacy-edge-runtime-config/app/legacy-runtime-config/page.js b/test/e2e/app-dir-legacy-edge-runtime-config/app/legacy-runtime-config/page.js index 5d8f880535..d1387c9d24 100644 --- a/test/e2e/app-dir-legacy-edge-runtime-config/app/legacy-runtime-config/page.js +++ b/test/e2e/app-dir-legacy-edge-runtime-config/app/legacy-runtime-config/page.js @@ -9,4 +9,5 @@ export default function Page() { export const config = { runtime: 'edge', + regions: ['us-east-1'], } diff --git a/test/e2e/app-dir-legacy-edge-runtime-config/index.test.ts b/test/e2e/app-dir-legacy-edge-runtime-config/index.test.ts index 23a1f111c4..628692f9f5 100644 --- a/test/e2e/app-dir-legacy-edge-runtime-config/index.test.ts +++ b/test/e2e/app-dir-legacy-edge-runtime-config/index.test.ts @@ -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"]`' ) }) }