From 00ebf1b9cc5e05b7d7b15ead9ff283e67275df98 Mon Sep 17 00:00:00 2001 From: Jiwon Choi Date: Wed, 8 Oct 2025 20:14:14 +0200 Subject: [PATCH] [backport] Add deprecation warning to Runtime config (#84168) Following up on https://github.com/vercel/next.js/pull/84167, adding a deprecation warning for the Runtime config. This PR will be backported to v15. --- packages/next/config.js | 13 ++++++++++++- packages/next/src/server/config-shared.ts | 6 ++++-- packages/next/src/server/config.ts | 13 +++++++++++++ .../src/shared/lib/runtime-config.external.ts | 6 ++++++ .../app/layout.tsx | 8 ++++++++ .../app/page.tsx | 6 ++++++ .../deprecation-warning-runtime-config.test.ts | 16 ++++++++++++++++ .../next.config.js | 13 +++++++++++++ .../deprecation-warnings.test.ts | 8 ++++++++ .../with-deprecated-config/next.config.js | 7 +++++++ 10 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 test/e2e/app-dir/deprecation-warning-runtime-config/app/layout.tsx create mode 100644 test/e2e/app-dir/deprecation-warning-runtime-config/app/page.tsx create mode 100644 test/e2e/app-dir/deprecation-warning-runtime-config/deprecation-warning-runtime-config.test.ts create mode 100644 test/e2e/app-dir/deprecation-warning-runtime-config/next.config.js diff --git a/packages/next/config.js b/packages/next/config.js index 668ee7c54f0e0..dd6f7b1f12536 100644 --- a/packages/next/config.js +++ b/packages/next/config.js @@ -1 +1,12 @@ -module.exports = require('./dist/shared/lib/runtime-config.external') +let hasWarned = false + +module.exports = (() => { + if (!hasWarned) { + console.warn( + // ANSI code aligns with Next.js warning style from picocolors. + ' \x1b[33m\x1b[1m⚠\x1b[22m\x1b[39m Runtime config is deprecated and will be removed in Next.js 16. Please remove the usage of "next/config" from your project.' + ) + hasWarned = true + } + return require('./dist/shared/lib/runtime-config.external') +})() diff --git a/packages/next/src/server/config-shared.ts b/packages/next/src/server/config-shared.ts index 42baaa7f1d85d..50c03b7d391ce 100644 --- a/packages/next/src/server/config-shared.ts +++ b/packages/next/src/server/config-shared.ts @@ -1235,14 +1235,16 @@ export interface NextConfig extends Record { /** * Add public (in browser) runtime configuration to your app * - * @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration + * @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration) + * @deprecated Runtime config is deprecated and will be removed in Next.js 16. */ publicRuntimeConfig?: { [key: string]: any } /** * Add server runtime configuration to your app * - * @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration + * @see [Runtime configuration](https://nextjs.org/docs/pages/api-reference/config/next-config-js/runtime-configuration) + * @deprecated Runtime config is deprecated and will be removed in Next.js 16. */ serverRuntimeConfig?: { [key: string]: any } diff --git a/packages/next/src/server/config.ts b/packages/next/src/server/config.ts index 3ed2e34398829..33483c1f4fd72 100644 --- a/packages/next/src/server/config.ts +++ b/packages/next/src/server/config.ts @@ -109,6 +109,19 @@ function checkDeprecations( silent ) + warnOptionHasBeenDeprecated( + userConfig, + 'publicRuntimeConfig', + `Runtime config is deprecated and the \`publicRuntimeConfig\` configuration option will be removed in Next.js 16.`, + silent + ) + warnOptionHasBeenDeprecated( + userConfig, + 'serverRuntimeConfig', + `Runtime config is deprecated and the \`serverRuntimeConfig\` configuration option will be removed in Next.js 16.`, + silent + ) + if (userConfig.experimental?.dynamicIO !== undefined) { warnOptionHasBeenDeprecated( userConfig, diff --git a/packages/next/src/shared/lib/runtime-config.external.ts b/packages/next/src/shared/lib/runtime-config.external.ts index b4a48a362d638..1a294922c94c8 100644 --- a/packages/next/src/shared/lib/runtime-config.external.ts +++ b/packages/next/src/shared/lib/runtime-config.external.ts @@ -1,9 +1,15 @@ let runtimeConfig: any +/** + * @deprecated Runtime config is deprecated and will be removed in Next.js 16. + */ export default () => { return runtimeConfig } +/** + * @deprecated Runtime config is deprecated and will be removed in Next.js 16. + */ export function setConfig(configValue: any): void { runtimeConfig = configValue } diff --git a/test/e2e/app-dir/deprecation-warning-runtime-config/app/layout.tsx b/test/e2e/app-dir/deprecation-warning-runtime-config/app/layout.tsx new file mode 100644 index 0000000000000..888614deda3ba --- /dev/null +++ b/test/e2e/app-dir/deprecation-warning-runtime-config/app/layout.tsx @@ -0,0 +1,8 @@ +import { ReactNode } from 'react' +export default function Root({ children }: { children: ReactNode }) { + return ( + + {children} + + ) +} diff --git a/test/e2e/app-dir/deprecation-warning-runtime-config/app/page.tsx b/test/e2e/app-dir/deprecation-warning-runtime-config/app/page.tsx new file mode 100644 index 0000000000000..b11185cc1000b --- /dev/null +++ b/test/e2e/app-dir/deprecation-warning-runtime-config/app/page.tsx @@ -0,0 +1,6 @@ +import getConfig from 'next/config' + +export default function Page() { + getConfig() + return

hello world

+} diff --git a/test/e2e/app-dir/deprecation-warning-runtime-config/deprecation-warning-runtime-config.test.ts b/test/e2e/app-dir/deprecation-warning-runtime-config/deprecation-warning-runtime-config.test.ts new file mode 100644 index 0000000000000..19c3bbfd403ce --- /dev/null +++ b/test/e2e/app-dir/deprecation-warning-runtime-config/deprecation-warning-runtime-config.test.ts @@ -0,0 +1,16 @@ +import { nextTestSetup } from 'e2e-utils' + +describe('deprecation-warning-runtime-config', () => { + const { next } = nextTestSetup({ + files: __dirname, + }) + + it('should warn when imported "next/config" module', async () => { + // Navigate to "/" for dev server to execute the code + await next.browser('/') + + expect(next.cliOutput).toContain( + 'Runtime config is deprecated and will be removed in Next.js 16. Please remove the usage of "next/config" from your project.' + ) + }) +}) diff --git a/test/e2e/app-dir/deprecation-warning-runtime-config/next.config.js b/test/e2e/app-dir/deprecation-warning-runtime-config/next.config.js new file mode 100644 index 0000000000000..789b3b853ebed --- /dev/null +++ b/test/e2e/app-dir/deprecation-warning-runtime-config/next.config.js @@ -0,0 +1,13 @@ +/** + * @type {import('next').NextConfig} + */ +const nextConfig = { + publicRuntimeConfig: { + foo: 'bar', + }, + serverRuntimeConfig: { + foo: 'bar', + }, +} + +module.exports = nextConfig diff --git a/test/e2e/deprecation-warnings/deprecation-warnings.test.ts b/test/e2e/deprecation-warnings/deprecation-warnings.test.ts index e120740e59398..251ba90d94d68 100644 --- a/test/e2e/deprecation-warnings/deprecation-warnings.test.ts +++ b/test/e2e/deprecation-warnings/deprecation-warnings.test.ts @@ -35,6 +35,14 @@ describe('deprecation-warnings', () => { // Should warn about experimental.instrumentationHook expect(logs).toContain('experimental.instrumentationHook') expect(logs).toContain('no longer needed') + + // Should warn about publicRuntimeConfig + expect(logs).toContain('publicRuntimeConfig') + expect(logs).toContain('will be removed in Next.js 16') + + // Should warn about serverRuntimeConfig + expect(logs).toContain('serverRuntimeConfig') + expect(logs).toContain('will be removed in Next.js 16') }) }) }) diff --git a/test/e2e/deprecation-warnings/fixtures/with-deprecated-config/next.config.js b/test/e2e/deprecation-warnings/fixtures/with-deprecated-config/next.config.js index d8d7c62c769ad..b2e8c3c6ca463 100644 --- a/test/e2e/deprecation-warnings/fixtures/with-deprecated-config/next.config.js +++ b/test/e2e/deprecation-warnings/fixtures/with-deprecated-config/next.config.js @@ -1,3 +1,4 @@ +/** @type {import('next').NextConfig} */ module.exports = { // Explicitly configure deprecated options amp: { @@ -6,4 +7,10 @@ module.exports = { experimental: { instrumentationHook: true, }, + publicRuntimeConfig: { + foo: 'bar', + }, + serverRuntimeConfig: { + foo: 'bar', + }, }