Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/giant-sites-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-vercel': minor
---

feat: Node 24 support
4 changes: 2 additions & 2 deletions packages/adapter-vercel/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function plugin(config?: Config): Adapter;

export interface ServerlessConfig {
/**
* Whether to use [Edge Functions](https://vercel.com/docs/concepts/functions/edge-functions) (`'edge'`) or [Serverless Functions](https://vercel.com/docs/concepts/functions/serverless-functions) (`'nodejs18.x'`, `'nodejs20.x'` etc).
* Whether to use [Edge Functions](https://vercel.com/docs/concepts/functions/edge-functions) (`'edge'`) or [Serverless Functions](https://vercel.com/docs/concepts/functions/serverless-functions) (`'nodejs22.x'`, `'nodejs24.x'` etc).
* @default Same as the build environment
*/
runtime?: Exclude<RuntimeConfigKey, 'edge'>;
Expand Down Expand Up @@ -78,7 +78,7 @@ type ImagesConfig = {
/** @deprecated */
export interface EdgeConfig {
/**
* Whether to use [Edge Functions](https://vercel.com/docs/concepts/functions/edge-functions) (`'edge'`) or [Serverless Functions](https://vercel.com/docs/concepts/functions/serverless-functions) (`'nodejs18.x'`, `'nodejs20.x'` etc).
* Whether to use [Edge Functions](https://vercel.com/docs/concepts/functions/edge-functions) (`'edge'`) or [Serverless Functions](https://vercel.com/docs/concepts/functions/serverless-functions) (`'nodejs22.x'`, `'nodejs24.x'` etc).
*/
runtime?: 'edge';
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ const plugin = function (defaults = {}) {

if (runtime === 'edge') {
throw new Error(
`${directory}: Routes using \`isr\` must use a Node.js or Bun runtime (for example 'nodejs22.x' or 'experimental_bun1.x')`
`${directory}: Routes using \`isr\` must use a Node.js or Bun runtime (for example 'nodejs24.x' or 'experimental_bun1.x')`
);
}

Expand Down
16 changes: 12 additions & 4 deletions packages/adapter-vercel/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,31 @@ export function resolve_runtime(default_key, override_key) {
return key;
}

const valid_node_versions = [20, 22, 24];

/** @returns {RuntimeKey} */
function get_default_runtime() {
// TODO may someday need to auto-detect Bun, but this will be complicated because you may want to run your build
// with Bun but not have your serverless runtime be in Bun. Vercel will likely have to attach something to `globalThis` or similar
// to tell us what the bun configuration is.
const major = Number(process.version.slice(1).split('.')[0]);

if (major !== 20 && major !== 22) {
if (!valid_node_versions.includes(major)) {
throw new Error(
`Unsupported Node.js version: ${process.version}. Please use Node 20 or 22 to build your project, or explicitly specify a runtime in your adapter configuration.`
`Unsupported Node.js version: ${process.version}. Please use Node ${valid_node_versions.slice(0, -1).join(', ')} or ${valid_node_versions.at(-1)} to build your project, or explicitly specify a runtime in your adapter configuration.`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, you can use Intl.ListFormat for automatic string enumeration from a list!

// (initiate the formatter as early and globally as possible; their creation is quite heavy AFAIK)
const formatter = new Intl.ListFormat("en", {
  type: "disjunction"
});

console.log(formatter.format(valid_node_versions)); // "20, 22, or 24"

(The Intl namespace is really awesome, I love it)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks, I totally forgot about this!

);
}

return `nodejs${major}.x`;
return `nodejs${/** @type {20 | 22 | 24} */ (major)}.x`;
}

const valid_runtimes = /** @type {const} */ (['nodejs20.x', 'nodejs22.x', 'bun1.x', 'edge']);
const valid_runtimes = /** @type {const} */ ([
'nodejs20.x',
'nodejs22.x',
'nodejs24.x',
'bun1.x',
'edge'
]);

/**
* @param {string} key
Expand Down
Loading