Skip to content

Commit 9c5bb5b

Browse files
styflebalazsorban44ijjk
authored
BREAKING CHANGE: Remove target: serverless (#41495)
The `target: serverless` config was deprecated a year ago starting in [Next.js 12](https://nextjs.org/blog/next-12). Tests were disabled in #41252 so we can now remove `target: serverless` and all usage of `target` in `next.config.js`. Co-authored-by: Balázs Orbán <info@balazsorban.com> Co-authored-by: JJ Kasper <jj@jjsweb.site>
1 parent ebae05e commit 9c5bb5b

File tree

224 files changed

+300
-5875
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+300
-5875
lines changed

docs/upgrading.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ A [codemod is available](/docs/advanced-features/codemods.md#next-image-to-legac
1515

1616
The `next/link` child can no longer be `<a>`. Add the `legacyBehavior` prop to use the legacy behavior or remove the `<a>` to upgrade. A [codemod is available](/docs/advanced-features/codemods.md#new-link) to automatically upgrade your code.
1717

18+
The `target` configuration option has been removed and superseded by [Output File Tracing](https://nextjs.org/docs/advanced-features/output-file-tracing).
19+
1820
## Upgrading to 12.2
1921

2022
If you were using Middleware prior to `12.2`, please see the [upgrade guide](https://nextjs.org/docs/messages/middleware-upgrade-guide) for more information.

errors/deprecated-target-config.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
#### Why This Error Occurred
44

5-
The `target` property in `next.config.js` has been deprecated. Please migrate to leverage the default target instead.
5+
Starting in Next.js 13, the `target` property in `next.config.js` has been removed.
66

77
#### Possible Ways to Fix It
88

9-
For serverless cases, leverage the new output file traces or deploy your application somewhere where they are leveraged automatically like [Vercel](https://vercel.com).
9+
For serverless targets, please use the Output File Tracing or deploy your application somewhere where it can be leveraged automatically, like [Vercel](https://vercel.com).
1010

1111
### Useful Links
1212

errors/gssp-export.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
You attempted to statically export your application via `next export`, however, one or more of your pages uses `getServerSideProps`.
66

7-
The `getServerSideProps` lifecycle is not compatible with `next export`, so you'll need to use `next start` or a [serverless deployment](https://vercel.com).
7+
The `getServerSideProps` lifecycle is not compatible with `next export`, so you'll need to use `next start` when self hosting or deploy to a provider like [Vercel](https://vercel.com).
88

99
#### Possible Ways to Fix It
1010

packages/next/build/entries.ts

-60
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { ClientPagesLoaderOptions } from './webpack/loaders/next-client-pag
22
import type { MiddlewareLoaderOptions } from './webpack/loaders/next-middleware-loader'
33
import type { EdgeSSRLoaderQuery } from './webpack/loaders/next-edge-ssr-loader'
44
import type { NextConfigComplete } from '../server/config-shared'
5-
import type { ServerlessLoaderQuery } from './webpack/loaders/next-serverless-loader'
65
import type { webpack } from 'next/dist/compiled/webpack/webpack'
76
import type {
87
MiddlewareConfig,
@@ -14,7 +13,6 @@ import { posix, join } from 'path'
1413
import { stringify } from 'querystring'
1514
import {
1615
API_ROUTE,
17-
DOT_NEXT_ALIAS,
1816
PAGES_DIR_ALIAS,
1917
ROOT_DIR_ALIAS,
2018
APP_DIR_ALIAS,
@@ -33,13 +31,11 @@ import {
3331
EDGE_RUNTIME_WEBPACK,
3432
} from '../shared/lib/constants'
3533
import { __ApiPreviewProps } from '../server/api-utils'
36-
import { isTargetLikeServerless } from '../server/utils'
3734
import { warn } from './output/log'
3835
import {
3936
isMiddlewareFile,
4037
isMiddlewareFilename,
4138
NestedMiddlewareError,
42-
MiddlewareInServerlessTargetError,
4339
} from './utils'
4440
import { getPageStaticInfo } from './analysis/get-page-static-info'
4541
import { normalizePathSep } from '../shared/lib/page-path/normalize-path-sep'
@@ -147,7 +143,6 @@ interface CreateEntrypointsParams {
147143
previewMode: __ApiPreviewProps
148144
rootDir: string
149145
rootPaths?: Record<string, string>
150-
target: 'server' | 'serverless' | 'experimental-serverless-trace'
151146
appDir?: string
152147
appPaths?: Record<string, string>
153148
pageExtensions: string[]
@@ -229,48 +224,6 @@ export function getAppEntry(opts: {
229224
}
230225
}
231226

232-
export function getServerlessEntry(opts: {
233-
absolutePagePath: string
234-
buildId: string
235-
config: NextConfigComplete
236-
envFiles: LoadedEnvFiles
237-
page: string
238-
previewMode: __ApiPreviewProps
239-
pages: { [page: string]: string }
240-
}): ObjectValue<webpack.EntryObject> {
241-
const loaderParams: ServerlessLoaderQuery = {
242-
absolute404Path: opts.pages['/404'] || '',
243-
absoluteAppPath: opts.pages['/_app'],
244-
absoluteDocumentPath: opts.pages['/_document'],
245-
absoluteErrorPath: opts.pages['/_error'],
246-
absolutePagePath: opts.absolutePagePath,
247-
assetPrefix: opts.config.assetPrefix,
248-
basePath: opts.config.basePath,
249-
buildId: opts.buildId,
250-
canonicalBase: opts.config.amp.canonicalBase || '',
251-
distDir: DOT_NEXT_ALIAS,
252-
generateEtags: opts.config.generateEtags ? 'true' : '',
253-
i18n: opts.config.i18n ? JSON.stringify(opts.config.i18n) : '',
254-
// base64 encode to make sure contents don't break webpack URL loading
255-
loadedEnvFiles: Buffer.from(JSON.stringify(opts.envFiles)).toString(
256-
'base64'
257-
),
258-
page: opts.page,
259-
poweredByHeader: opts.config.poweredByHeader ? 'true' : '',
260-
previewProps: JSON.stringify(opts.previewMode),
261-
runtimeConfig:
262-
Object.keys(opts.config.publicRuntimeConfig).length > 0 ||
263-
Object.keys(opts.config.serverRuntimeConfig).length > 0
264-
? JSON.stringify({
265-
publicRuntimeConfig: opts.config.publicRuntimeConfig,
266-
serverRuntimeConfig: opts.config.serverRuntimeConfig,
267-
})
268-
: '',
269-
}
270-
271-
return `next-serverless-loader?${stringify(loaderParams)}!`
272-
}
273-
274227
export function getClientEntry(opts: {
275228
absolutePagePath: string
276229
page: string
@@ -340,7 +293,6 @@ export async function createEntrypoints(params: CreateEntrypointsParams) {
340293
isDev,
341294
rootDir,
342295
rootPaths,
343-
target,
344296
appDir,
345297
appPaths,
346298
pageExtensions,
@@ -428,10 +380,6 @@ export async function createEntrypoints(params: CreateEntrypointsParams) {
428380
middlewareMatchers = staticInfo.middleware?.matchers ?? [
429381
{ regexp: '.*' },
430382
]
431-
432-
if (target === 'serverless') {
433-
throw new MiddlewareInServerlessTargetError()
434-
}
435383
}
436384

437385
await runDependingOnPageType({
@@ -459,14 +407,6 @@ export async function createEntrypoints(params: CreateEntrypointsParams) {
459407
appPaths: matchedAppPaths,
460408
pageExtensions,
461409
})
462-
} else if (isTargetLikeServerless(target)) {
463-
if (page !== '/_app' && page !== '/_document') {
464-
server[serverBundlePath] = getServerlessEntry({
465-
...params,
466-
absolutePagePath: mappings[page],
467-
page,
468-
})
469-
}
470410
} else {
471411
server[serverBundlePath] = [mappings[page]]
472412
}

0 commit comments

Comments
 (0)