Skip to content

Commit 20df748

Browse files
authored
chore: support building with Node 22 (#13043)
Also adjust the validation logic to not care at all when building on Vercel, to not have to update the adapter each time right away. Closes #13040
1 parent a3ef25f commit 20df748

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

.changeset/long-rivers-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-vercel': patch
3+
---
4+
5+
chore: support building with Node 22

documentation/docs/25-build-and-deploy/90-adapter-vercel.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ export const config = {
4444
/// file: admin/+layout.js
4545
/** @type {import('@sveltejs/adapter-vercel').Config} */
4646
export const config = {
47-
runtime: 'nodejs18.x'
47+
runtime: 'nodejs22.x'
4848
};
4949
```
5050

5151
The following options apply to all functions:
5252

53-
- `runtime`: `'edge'`, `'nodejs18.x'` or `'nodejs20.x'`. By default, the adapter will select the `'nodejs<version>.x'` corresponding to the Node version your project is configured to use on the Vercel dashboard
53+
- `runtime`: `'edge'`, `'nodejs18.x'`, `'nodejs20.x'` or `'nodejs22.x'`. By default, the adapter will select the `'nodejs<version>.x'` corresponding to the Node version your project is configured to use on the Vercel dashboard
5454
- `regions`: an array of [edge network regions](https://vercel.com/docs/concepts/edge-network/regions) (defaulting to `["iad1"]` for serverless functions) or `'all'` if `runtime` is `edge` (its default). Note that multiple regions for serverless functions are only supported on Enterprise plans
5555
- `split`: if `true`, causes a route to be deployed as an individual function. If `split` is set to `true` at the adapter level, all routes will be deployed as individual functions
5656

packages/adapter-vercel/index.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,27 @@ const name = '@sveltejs/adapter-vercel';
1111
const DEFAULT_FUNCTION_NAME = 'fn';
1212

1313
const get_default_runtime = () => {
14-
const major = process.version.slice(1).split('.')[0];
15-
if (major === '18') return 'nodejs18.x';
16-
if (major === '20') return 'nodejs20.x';
14+
const major = Number(process.version.slice(1).split('.')[0]);
15+
16+
// If we're building on Vercel, we know that the version will be fine because Vercel
17+
// provides Node (and Vercel won't provide something it doesn't support).
18+
// Also means we're not on the hook for updating the adapter every time a new Node
19+
// version is added to Vercel.
20+
if (!process.env.VERCEL) {
21+
if (major < 18 || major > 22) {
22+
throw new Error(
23+
`Building locally with unsupported Node.js version: ${process.version}. Please use Node 18, 20 or 22 to build your project, or explicitly specify a runtime in your adapter configuration.`
24+
);
25+
}
1726

18-
throw new Error(
19-
`Unsupported Node.js version: ${process.version}. Please use Node 18 or Node 20 to build your project, or explicitly specify a runtime in your adapter configuration.`
20-
);
27+
if (major % 2 !== 0) {
28+
throw new Error(
29+
`Unsupported Node.js version: ${process.version}. Please use an even-numbered Node version to build your project, or explicitly specify a runtime in your adapter configuration.`
30+
);
31+
}
32+
}
33+
34+
return `nodejs${major}.x`;
2135
};
2236

2337
// https://vercel.com/docs/functions/edge-functions/edge-runtime#compatible-node.js-modules

0 commit comments

Comments
 (0)