From d553240e244a5dc4a88682baa96ec813fa0fd233 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Fri, 22 Nov 2024 17:56:00 +0100 Subject: [PATCH 1/3] chore: support building with Node 22 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 --- .changeset/long-rivers-stare.md | 5 +++++ packages/adapter-vercel/index.js | 25 +++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 .changeset/long-rivers-stare.md diff --git a/.changeset/long-rivers-stare.md b/.changeset/long-rivers-stare.md new file mode 100644 index 000000000000..8247736f92a9 --- /dev/null +++ b/.changeset/long-rivers-stare.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-vercel': patch +--- + +chore: support building with Node 22 diff --git a/packages/adapter-vercel/index.js b/packages/adapter-vercel/index.js index bb9114a0c10e..ea4fec4e3e20 100644 --- a/packages/adapter-vercel/index.js +++ b/packages/adapter-vercel/index.js @@ -11,13 +11,26 @@ const name = '@sveltejs/adapter-vercel'; const DEFAULT_FUNCTION_NAME = 'fn'; const get_default_runtime = () => { - const major = process.version.slice(1).split('.')[0]; - if (major === '18') return 'nodejs18.x'; - if (major === '20') return 'nodejs20.x'; + const major = Number(process.version.slice(1).split('.')[0]); + + // If we're building on Vercel, we know that the version will be fine. Also means + // we're not on the hook for updating the adapter every time a new Node version is + // added to Vercel. + if (!process.env.VERCEL) { + if (major < 18 || major > 22) { + throw new Error( + `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.` + ); + } - throw new Error( - `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.` - ); + if (major % 2 !== 0) { + throw new Error( + `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.` + ); + } + } + + return `nodejs${major}.x`; }; // https://vercel.com/docs/functions/edge-functions/edge-runtime#compatible-node.js-modules From 3018f10c87d08a8776340a667b06408a509eea45 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Fri, 22 Nov 2024 17:58:56 +0100 Subject: [PATCH 2/3] docs --- documentation/docs/25-build-and-deploy/90-adapter-vercel.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/docs/25-build-and-deploy/90-adapter-vercel.md b/documentation/docs/25-build-and-deploy/90-adapter-vercel.md index 57867ce7c986..f8150c0fd7cd 100644 --- a/documentation/docs/25-build-and-deploy/90-adapter-vercel.md +++ b/documentation/docs/25-build-and-deploy/90-adapter-vercel.md @@ -44,13 +44,13 @@ export const config = { /// file: admin/+layout.js /** @type {import('@sveltejs/adapter-vercel').Config} */ export const config = { - runtime: 'nodejs18.x' + runtime: 'nodejs22.x' }; ``` The following options apply to all functions: -- `runtime`: `'edge'`, `'nodejs18.x'` or `'nodejs20.x'`. By default, the adapter will select the `'nodejs.x'` corresponding to the Node version your project is configured to use on the Vercel dashboard +- `runtime`: `'edge'`, `'nodejs18.x'`, `'nodejs20.x'` or `'nodejs22.x'`. By default, the adapter will select the `'nodejs.x'` corresponding to the Node version your project is configured to use on the Vercel dashboard - `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 - `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 From c5dd3680bf9e7b9278ea14b914e0f990f294cda5 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 22 Nov 2024 20:57:36 +0100 Subject: [PATCH 3/3] Update packages/adapter-vercel/index.js --- packages/adapter-vercel/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/adapter-vercel/index.js b/packages/adapter-vercel/index.js index ea4fec4e3e20..3fdd2f027b66 100644 --- a/packages/adapter-vercel/index.js +++ b/packages/adapter-vercel/index.js @@ -13,9 +13,10 @@ const DEFAULT_FUNCTION_NAME = 'fn'; const get_default_runtime = () => { const major = Number(process.version.slice(1).split('.')[0]); - // If we're building on Vercel, we know that the version will be fine. Also means - // we're not on the hook for updating the adapter every time a new Node version is - // added to Vercel. + // If we're building on Vercel, we know that the version will be fine because Vercel + // provides Node (and Vercel won't provide something it doesn't support). + // Also means we're not on the hook for updating the adapter every time a new Node + // version is added to Vercel. if (!process.env.VERCEL) { if (major < 18 || major > 22) { throw new Error(