From 7486bbfa5ebdf6d863b1151d4f540b25d41099c9 Mon Sep 17 00:00:00 2001 From: Vincent Voyer Date: Thu, 24 Aug 2023 12:32:09 +0200 Subject: [PATCH 1/5] fix(error messages): Provide more precise error messages for export const config 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. --- .../src/build/analysis/get-page-static-info.ts | 17 ++++++++++++++++- .../app/legacy-runtime-config/page.js | 1 + .../index.test.ts | 11 +++++++++-- 3 files changed, 26 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 9951b583b1f04..4e3c2e3346284 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 = `\`export const config\` in ${pageFilePath} is deprecated:` + + if (config.runtime) { + message += `\n - Change \`config.runtime…\` to \`export const runtime = ${JSON.stringify( + config.runtime + )}\`` + } + + if (config.regions) { + message += `\n - Change \`config.regions…\` to \`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 5d8f880535531..d1387c9d24020 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 23a1f111c4dc3..d52945adc69f2 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,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"]`' ) }) } From 44b47d213ede4455fe9bdf5ea7dc40c3b5657787 Mon Sep 17 00:00:00 2001 From: Vincent Voyer Date: Fri, 25 Aug 2023 08:33:58 +0200 Subject: [PATCH 2/5] Update packages/next/src/build/analysis/get-page-static-info.ts Co-authored-by: Steven --- packages/next/src/build/analysis/get-page-static-info.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4e3c2e3346284..85ec5fe6f0cef 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,7 @@ export async function getPageStaticInfo(params: { if (pageType === 'app') { if (config) { - let message = `\`export const config\` in ${pageFilePath} is deprecated:` + let message = `Page config in ${pageFilePath} is deprecated. Replace \`export const config=…\` with the following:` if (config.runtime) { message += `\n - Change \`config.runtime…\` to \`export const runtime = ${JSON.stringify( From 7df0e16223200b12f4ca9bbac0fcb1ae38feb6c1 Mon Sep 17 00:00:00 2001 From: Vincent Voyer Date: Fri, 25 Aug 2023 08:34:23 +0200 Subject: [PATCH 3/5] Update packages/next/src/build/analysis/get-page-static-info.ts Co-authored-by: Steven --- packages/next/src/build/analysis/get-page-static-info.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 85ec5fe6f0cef..921461bca6c7e 100644 --- a/packages/next/src/build/analysis/get-page-static-info.ts +++ b/packages/next/src/build/analysis/get-page-static-info.ts @@ -530,7 +530,7 @@ export async function getPageStaticInfo(params: { let message = `Page config in ${pageFilePath} is deprecated. Replace \`export const config=…\` with the following:` if (config.runtime) { - message += `\n - Change \`config.runtime…\` to \`export const runtime = ${JSON.stringify( + message += `\n - \`export const runtime = ${JSON.stringify( config.runtime )}\`` } From 2bb7d6f4dd8c469225781e43736f8b661a44c8f5 Mon Sep 17 00:00:00 2001 From: Vincent Voyer Date: Fri, 25 Aug 2023 08:34:30 +0200 Subject: [PATCH 4/5] Update packages/next/src/build/analysis/get-page-static-info.ts Co-authored-by: Steven --- packages/next/src/build/analysis/get-page-static-info.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 921461bca6c7e..6d6cc421f895f 100644 --- a/packages/next/src/build/analysis/get-page-static-info.ts +++ b/packages/next/src/build/analysis/get-page-static-info.ts @@ -536,7 +536,7 @@ export async function getPageStaticInfo(params: { } if (config.regions) { - message += `\n - Change \`config.regions…\` to \`export const preferredRegion = ${JSON.stringify( + message += `\n - \`export const preferredRegion = ${JSON.stringify( config.regions )}\`` } From 1f70db24f68f0d367b2193826124b7fe45ddd7a8 Mon Sep 17 00:00:00 2001 From: Vincent Voyer Date: Fri, 25 Aug 2023 09:06:34 +0200 Subject: [PATCH 5/5] update test --- .../app-dir-legacy-edge-runtime-config/index.test.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 d52945adc69f2..628692f9f56ad 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,16 +19,15 @@ createNextDescribe( } else { expect(error).toBeDefined() } - expect(next.cliOutput).toContain('`export const config` in') + + expect(next.cliOutput).toContain('Page config in ') expect(next.cliOutput).toContain( // 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"' + '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( - '- Change `config.regions…` to `export const preferredRegion = ["us-east-1"]`' + '- `export const preferredRegion = ["us-east-1"]`' ) }) }