Commit a094eab7 authored by Tim Neutkens's avatar Tim Neutkens

Deprecate edge runtime

parent b6cf70eb
...@@ -561,7 +561,7 @@ const secretKey = process.env.SESSION_SECRET ...@@ -561,7 +561,7 @@ const secretKey = process.env.SESSION_SECRET
#### 2. Encrypting and decrypting sessions #### 2. Encrypting and decrypting sessions
Next, you can use your preferred [session management library](#session-management-libraries) to encrypt and decrypt sessions. Continuing from the previous example, we'll use [Jose](https://www.npmjs.com/package/jose) (compatible with the [Edge Runtime](/docs/app/api-reference/edge)) and React's [`server-only`](https://www.npmjs.com/package/server-only) package to ensure that your session management logic is only executed on the server. Next, you can use your preferred [session management library](#session-management-libraries) to encrypt and decrypt sessions. Continuing from the previous example, we'll use [Jose](https://www.npmjs.com/package/jose) and React's [`server-only`](https://www.npmjs.com/package/server-only) package to ensure that your session management logic is only executed on the server.
```tsx filename="app/lib/session.ts" switcher ```tsx filename="app/lib/session.ts" switcher
import 'server-only' import 'server-only'
...@@ -1121,7 +1121,7 @@ While Proxy can be useful for initial checks, it should not be your only line of ...@@ -1121,7 +1121,7 @@ While Proxy can be useful for initial checks, it should not be your only line of
> **Tips**: > **Tips**:
> >
> - In Proxy, you can also read cookies using `req.cookies.get('session').value`. > - In Proxy, you can also read cookies using `req.cookies.get('session').value`.
> - Proxy uses the Node.js runtime, check if your Auth library and session management library are compatible. You may need to use [Middleware](https://github.com/vercel/next.js/blob/v15.5.6/docs/01-app/03-api-reference/03-file-conventions/middleware.mdx) if your Auth library only supports [Edge Runtime](/docs/app/api-reference/edge) > - Proxy uses the Node.js runtime, check if your Auth library and session management library are compatible.
> - You can use the `matcher` property in the Proxy to specify which routes Proxy should run on. Although, for auth, it's recommended Proxy runs on all routes. > - You can use the `matcher` property in the Proxy to specify which routes Proxy should run on. Although, for auth, it's recommended Proxy runs on all routes.
<AppOnly> <AppOnly>
......
...@@ -183,7 +183,7 @@ export const revalidate = false ...@@ -183,7 +183,7 @@ export const revalidate = false
> **Good to know**: > **Good to know**:
> >
> - The revalidate value needs to be statically analyzable. For example `revalidate = 600` is valid, but `revalidate = 60 * 10` is not. > - The revalidate value needs to be statically analyzable. For example `revalidate = 600` is valid, but `revalidate = 60 * 10` is not.
> - The revalidate value is not available when using `runtime = 'edge'`. > - The revalidate value is not available when using the deprecated `runtime = 'edge'`.
> - In Development, Pages are _always_ rendered on-demand and are never cached. This allows you to see changes immediately without waiting for a revalidation period to pass. > - In Development, Pages are _always_ rendered on-demand and are never cached. This allows you to see changes immediately without waiting for a revalidation period to pass.
#### Revalidation frequency #### Revalidation frequency
......
...@@ -172,4 +172,4 @@ export default async function Page() { ...@@ -172,4 +172,4 @@ export default async function Page() {
## `runtime = 'edge'` ## `runtime = 'edge'`
**Not supported.** Cache Components requires the Node.js runtime. Switch to the Node.js runtime (the default) by removing the `runtime = 'edge'` export. If you need edge behavior for specific routes, use [Proxy](/docs/app/api-reference/file-conventions/proxy) instead. **Not supported.** The Edge Runtime is [deprecated](/docs/messages/edge-runtime-deprecated) and Cache Components requires the Node.js runtime. Remove the `runtime = 'edge'` export from your route files.
...@@ -30,8 +30,6 @@ Image Optimization can be used with a [static export](/docs/app/guides/static-ex ...@@ -30,8 +30,6 @@ Image Optimization can be used with a [static export](/docs/app/guides/static-ex
[Proxy](/docs/app/api-reference/file-conventions/proxy) works self-hosted with zero configuration when deploying using `next start`. Since it requires access to the incoming request, it is not supported when using a [static export](/docs/app/guides/static-exports). [Proxy](/docs/app/api-reference/file-conventions/proxy) works self-hosted with zero configuration when deploying using `next start`. Since it requires access to the incoming request, it is not supported when using a [static export](/docs/app/guides/static-exports).
Proxy uses the [Edge runtime](/docs/app/api-reference/edge), a subset of all available Node.js APIs to help ensure low latency, since it may run in front of every route or asset in your application. If you do not want this, you can use the [full Node.js runtime](/blog/next-15-2#nodejs-middleware-experimental) to run Proxy.
If you are looking to add logic (or use an external package) that requires all Node.js APIs, you might be able to move this logic to a [layout](/docs/app/api-reference/file-conventions/layout) as a [Server Component](/docs/app/getting-started/server-and-client-components). For example, checking [headers](/docs/app/api-reference/functions/headers) and [redirecting](/docs/app/api-reference/functions/redirect). You can also use headers, cookies, or query parameters to [redirect](/docs/app/api-reference/config/next-config-js/redirects#header-cookie-and-query-matching) or [rewrite](/docs/app/api-reference/config/next-config-js/rewrites#header-cookie-and-query-matching) through `next.config.js`. If that does not work, you can also use a [custom server](/docs/pages/guides/custom-server). If you are looking to add logic (or use an external package) that requires all Node.js APIs, you might be able to move this logic to a [layout](/docs/app/api-reference/file-conventions/layout) as a [Server Component](/docs/app/getting-started/server-and-client-components). For example, checking [headers](/docs/app/api-reference/functions/headers) and [redirecting](/docs/app/api-reference/functions/redirect). You can also use headers, cookies, or query parameters to [redirect](/docs/app/api-reference/config/next-config-js/redirects#header-cookie-and-query-matching) or [rewrite](/docs/app/api-reference/config/next-config-js/rewrites#header-cookie-and-query-matching) through `next.config.js`. If that does not work, you can also use a [custom server](/docs/pages/guides/custom-server).
## Environment Variables ## Environment Variables
......
...@@ -8,7 +8,7 @@ The Route Segment Config options allow you to configure the behavior of a [Page] ...@@ -8,7 +8,7 @@ The Route Segment Config options allow you to configure the behavior of a [Page]
| Option | Type | Default | | Option | Type | Default |
| -------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | -------------------------- | | -------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | -------------------------- |
| [`dynamicParams`](/docs/app/api-reference/file-conventions/route-segment-config/dynamicParams) | `boolean` | `true` | | [`dynamicParams`](/docs/app/api-reference/file-conventions/route-segment-config/dynamicParams) | `boolean` | `true` |
| [`runtime`](/docs/app/api-reference/file-conventions/route-segment-config/runtime) | `'nodejs' \| 'edge'` | `'nodejs'` | | [`runtime`](/docs/app/api-reference/file-conventions/route-segment-config/runtime) | `'nodejs' \| 'edge' (deprecated)` | `'nodejs'` |
| [`preferredRegion`](/docs/app/api-reference/file-conventions/route-segment-config/preferredRegion) | `'auto' \| 'global' \| 'home' \| string \| string[]` | `'auto'` | | [`preferredRegion`](/docs/app/api-reference/file-conventions/route-segment-config/preferredRegion) | `'auto' \| 'global' \| 'home' \| string \| string[]` | `'auto'` |
| [`maxDuration`](/docs/app/api-reference/file-conventions/route-segment-config/maxDuration) | `number` | Set by deployment platform | | [`maxDuration`](/docs/app/api-reference/file-conventions/route-segment-config/maxDuration) | `number` | Set by deployment platform |
......
...@@ -24,7 +24,7 @@ export const preferredRegion = // string || string[] ...@@ -24,7 +24,7 @@ export const preferredRegion = // string || string[]
## Vercel ## Vercel
If deploying Next.js on Vercel, regions are only supported if `export const runtime = 'edge'` is set. The following options can be passed: If deploying Next.js on Vercel, regions were previously only supported with `export const runtime = 'edge'`, which is now [deprecated](/docs/messages/edge-runtime-deprecated). The following options can be passed:
- **`'auto'`** (default): Uses the default region. - **`'auto'`** (default): Uses the default region.
- **`'global'`**: Prefer deploying the route to all availableregions. - **`'global'`**: Prefer deploying the route to all availableregions.
......
...@@ -7,18 +7,18 @@ The `runtime` option allows you to select the JavaScript runtime used for render ...@@ -7,18 +7,18 @@ The `runtime` option allows you to select the JavaScript runtime used for render
```tsx filename="layout.tsx | page.tsx | route.ts" switcher ```tsx filename="layout.tsx | page.tsx | route.ts" switcher
export const runtime = 'nodejs' export const runtime = 'nodejs'
// 'nodejs' | 'edge' // 'nodejs'
``` ```
```js filename="layout.js | page.js | route.js" switcher ```js filename="layout.js | page.js | route.js" switcher
export const runtime = 'nodejs' export const runtime = 'nodejs'
// 'nodejs' | 'edge' // 'nodejs'
``` ```
- **`'nodejs'`** (default) - **`'nodejs'`** (default)
- **`'edge'`** - **`'edge'`** (deprecated)
> **Good to know**: > **Good to know**:
> >
> - Using `runtime: 'edge'` is **not supported** for Cache Components. > - The Edge Runtime is deprecated. Remove the `runtime` export from your route files. See [Edge Runtime Deprecated](/docs/messages/edge-runtime-deprecated).
> - This option cannot be used in [Proxy](/docs/app/api-reference/file-conventions/proxy). > - This option cannot be used in [Proxy](/docs/app/api-reference/file-conventions/proxy).
...@@ -229,7 +229,7 @@ In addition, a number of built-in conditions are supported: ...@@ -229,7 +229,7 @@ In addition, a number of built-in conditions are supported:
- `development`: Matches when using `next dev`. - `development`: Matches when using `next dev`.
- `production`: Matches when using `next build`. - `production`: Matches when using `next build`.
- `node`: Matches code that will run on the default Node.js runtime. - `node`: Matches code that will run on the default Node.js runtime.
- `edge-light`: Matches code that will run on the [Edge runtime](/docs/app/api-reference/edge). - `edge-light`: Matches code that will run on the [Edge runtime](/docs/app/api-reference/edge) (deprecated).
Rules can be an object or an array of objects. An array is often useful for modeling disjoint conditions: Rules can be an object or an array of objects. An array is often useful for modeling disjoint conditions:
......
...@@ -48,7 +48,9 @@ Relevant files in the Next.js core: ...@@ -48,7 +48,9 @@ Relevant files in the Next.js core:
- [`packages/next/src/build/templates/app-route.ts`](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/app-route.ts) - [`packages/next/src/build/templates/app-route.ts`](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/app-route.ts)
- and [`packages/next/src/build/templates/pages-api.ts`](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/pages-api.ts) - and [`packages/next/src/build/templates/pages-api.ts`](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/pages-api.ts)
## Edge runtime (`runtime: 'edge'`) ## Edge runtime (`runtime: 'edge'`) (deprecated)
> The Edge Runtime is [deprecated](/docs/messages/edge-runtime-deprecated). New routes should use the Node.js runtime.
Edge entrypoints use the following interface: Edge entrypoints use the following interface:
......
...@@ -15,7 +15,7 @@ The `outputs` object contains arrays of build output types: ...@@ -15,7 +15,7 @@ The `outputs` object contains arrays of build output types:
> **Note:** When `config.output` is set to `'export'`, only `outputs.staticFiles` is populated. All other arrays (`pages`, `appPages`, `pagesApi`, `appRoutes`, `prerenders`) will be empty since the entire application is exported as static files. > **Note:** When `config.output` is set to `'export'`, only `outputs.staticFiles` is populated. All other arrays (`pages`, `appPages`, `pagesApi`, `appRoutes`, `prerenders`) will be empty since the entire application is exported as static files.
For any route output with `runtime: 'edge'`, `edgeRuntime` is included and contains the canonical entry metadata for invoking that output in your edge runtime. For any route output with `runtime: 'edge'`, `edgeRuntime` is included and contains the canonical entry metadata for invoking that output in your edge runtime. Note that the Edge Runtime is [deprecated](/docs/messages/edge-runtime-deprecated).
## Pages (`outputs.pages`) ## Pages (`outputs.pages`)
......
---
title: Edge Runtime Deprecated
---
## Why This Warning Occurred
One or more routes in your application use `export const runtime = 'edge'`, which is deprecated.
## How to Migrate
Remove the `runtime` export from your route files:
```diff
- export const runtime = 'edge'
```
The Node.js runtime is the default, so no replacement is needed.
This applies to all route files that support the `runtime` segment config: `page.ts`, `layout.ts`, `route.ts`, and API routes.
## Useful Links
- [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config#runtime)
...@@ -15,6 +15,7 @@ import { ...@@ -15,6 +15,7 @@ import {
import { tryToParsePath } from '../../lib/try-to-parse-path' import { tryToParsePath } from '../../lib/try-to-parse-path'
import { isAPIRoute } from '../../lib/is-api-route' import { isAPIRoute } from '../../lib/is-api-route'
import { isEdgeRuntime } from '../../lib/is-edge-runtime' import { isEdgeRuntime } from '../../lib/is-edge-runtime'
import { warnAboutEdgeRuntime } from '../warn-about-edge-runtime'
import { RSC_MODULE_TYPES } from '../../shared/lib/constants' import { RSC_MODULE_TYPES } from '../../shared/lib/constants'
import type { RSCMeta } from '../webpack/loaders/get-module-build-info' import type { RSCMeta } from '../webpack/loaders/get-module-build-info'
import { PAGE_TYPES } from '../../lib/page-types' import { PAGE_TYPES } from '../../lib/page-types'
...@@ -721,6 +722,10 @@ export async function getAppPageStaticInfo({ ...@@ -721,6 +722,10 @@ export async function getAppPageStaticInfo({
) )
} }
if (isEdgeRuntime(config.runtime)) {
warnAboutEdgeRuntime()
}
return { return {
type: PAGE_TYPES.APP, type: PAGE_TYPES.APP,
rsc, rsc,
...@@ -831,6 +836,10 @@ export async function getPagesPageStaticInfo({ ...@@ -831,6 +836,10 @@ export async function getPagesPageStaticInfo({
} }
} }
if (isEdgeRuntime(resolvedRuntime)) {
warnAboutEdgeRuntime()
}
return { return {
type: PAGE_TYPES.PAGES, type: PAGE_TYPES.PAGES,
getStaticProps, getStaticProps,
......
import * as Log from './output/log'
export function warnAboutEdgeRuntime() {
Log.warnOnce(
`The Edge Runtime is deprecated. You can use the "nodejs" runtime instead. Learn more: https://nextjs.org/docs/messages/edge-runtime-deprecated`
)
}
...@@ -15,6 +15,7 @@ import { ...@@ -15,6 +15,7 @@ import {
HMR_MESSAGE_SENT_TO_BROWSER, HMR_MESSAGE_SENT_TO_BROWSER,
} from './hot-reloader-types' } from './hot-reloader-types'
import * as Log from '../../build/output/log' import * as Log from '../../build/output/log'
import { warnAboutEdgeRuntime } from '../../build/warn-about-edge-runtime'
import type { PropagateToWorkersField } from '../lib/router-utils/types' import type { PropagateToWorkersField } from '../lib/router-utils/types'
import type { TurbopackManifestLoader } from '../../shared/lib/turbopack/manifest-loader' import type { TurbopackManifestLoader } from '../../shared/lib/turbopack/manifest-loader'
import type { AppRoute, Entrypoints, PageRoute } from '../../build/swc/types' import type { AppRoute, Entrypoints, PageRoute } from '../../build/swc/types'
...@@ -227,6 +228,7 @@ export async function handleRouteType({ ...@@ -227,6 +228,7 @@ export async function handleRouteType({
await manifestLoader.loadBuildManifest(page) await manifestLoader.loadBuildManifest(page)
await manifestLoader.loadPagesManifest(page) await manifestLoader.loadPagesManifest(page)
if (type === 'edge') { if (type === 'edge') {
warnAboutEdgeRuntime()
await manifestLoader.loadMiddlewareManifest(page, 'pages') await manifestLoader.loadMiddlewareManifest(page, 'pages')
} else { } else {
manifestLoader.deleteMiddlewareManifest(serverKey) manifestLoader.deleteMiddlewareManifest(serverKey)
...@@ -320,6 +322,7 @@ export async function handleRouteType({ ...@@ -320,6 +322,7 @@ export async function handleRouteType({
await manifestLoader.loadPagesManifest(page) await manifestLoader.loadPagesManifest(page)
if (type === 'edge') { if (type === 'edge') {
warnAboutEdgeRuntime()
await manifestLoader.loadMiddlewareManifest(page, 'pages') await manifestLoader.loadMiddlewareManifest(page, 'pages')
} else { } else {
manifestLoader.deleteMiddlewareManifest(key) manifestLoader.deleteMiddlewareManifest(key)
...@@ -373,6 +376,7 @@ export async function handleRouteType({ ...@@ -373,6 +376,7 @@ export async function handleRouteType({
const type = writtenEndpoint.type const type = writtenEndpoint.type
if (type === 'edge') { if (type === 'edge') {
warnAboutEdgeRuntime()
manifestLoader.loadMiddlewareManifest(page, 'app') manifestLoader.loadMiddlewareManifest(page, 'app')
} else { } else {
manifestLoader.deleteMiddlewareManifest(key) manifestLoader.deleteMiddlewareManifest(key)
...@@ -404,6 +408,7 @@ export async function handleRouteType({ ...@@ -404,6 +408,7 @@ export async function handleRouteType({
manifestLoader.loadAppPathsManifest(page) manifestLoader.loadAppPathsManifest(page)
if (type === 'edge') { if (type === 'edge') {
warnAboutEdgeRuntime()
manifestLoader.loadMiddlewareManifest(page, 'app') manifestLoader.loadMiddlewareManifest(page, 'app')
} else { } else {
manifestLoader.deleteMiddlewareManifest(key) manifestLoader.deleteMiddlewareManifest(key)
......
...@@ -124,7 +124,7 @@ const API_DOCS: Record< ...@@ -124,7 +124,7 @@ const API_DOCS: Record<
'The `runtime` option controls the preferred runtime to render this route.', 'The `runtime` option controls the preferred runtime to render this route.',
options: { options: {
'"nodejs"': 'Prefer the Node.js runtime.', '"nodejs"': 'Prefer the Node.js runtime.',
'"edge"': 'Prefer the Edge runtime.', '"edge"': `@deprecated\n\nThe Edge Runtime is deprecated. Use \`"nodejs"\` instead.`,
'"experimental-edge"': `@deprecated\n\nThis option is no longer experimental. Use \`edge\` instead.`, '"experimental-edge"': `@deprecated\n\nThis option is no longer experimental. Use \`edge\` instead.`,
} satisfies DocsOptionsObject< } satisfies DocsOptionsObject<
FullAppSegmentConfig['runtime'] | 'experimental-edge' FullAppSegmentConfig['runtime'] | 'experimental-edge'
......
export const runtime = 'edge'
export function GET() {
return new Response('edge route')
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
export default function Page() {
return <p>Hello</p>
}
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
const EXPECTED_WARNING =
'The Edge Runtime is deprecated. You can use the "nodejs" runtime instead.'
describe('edge-runtime-deprecated', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
it('should warn about deprecated edge runtime', async () => {
if (isNextDev) {
// In dev mode, the warning fires when the edge route is first compiled.
await next.fetch('/edge-route')
}
await retry(async () => {
expect(next.cliOutput).toContain(EXPECTED_WARNING)
})
})
it('should only warn once', async () => {
if (isNextDev) {
// Trigger compilation of the edge route again (already compiled, but
// another request ensures no duplicate warnings).
await next.fetch('/edge-route')
}
await retry(async () => {
expect(next.cliOutput).toContain(EXPECTED_WARNING)
})
const occurrences = next.cliOutput.split(EXPECTED_WARNING).length - 1
expect(occurrences).toBe(1)
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment