diff --git a/src/presets/vercel/utils.ts b/src/presets/vercel/utils.ts index 275a9ae4ce..a15c6cd2f0 100644 --- a/src/presets/vercel/utils.ts +++ b/src/presets/vercel/utils.ts @@ -10,13 +10,28 @@ import type { VercelServerlessFunctionConfig, } from "./types"; +// https://vercel.com/docs/functions/runtimes/node-js/node-js-versions +const SUPPORTED_NODE_VERSIONS = [16, 18, 20, 22]; + +function getSystemNodeVersion() { + const systemNodeVersion = Number.parseInt( + process.versions.node.split(".")[0] + ); + + return Number.isNaN(systemNodeVersion) ? 20 : systemNodeVersion; +} + export async function generateFunctionFiles(nitro: Nitro) { const buildConfigPath = resolve(nitro.options.output.dir, "config.json"); const buildConfig = generateBuildConfig(nitro); await writeFile(buildConfigPath, JSON.stringify(buildConfig, null, 2)); - const systemNodeVersion = process.versions.node.split(".")[0]; - const runtimeVersion = `nodejs${systemNodeVersion}.x`; + const systemNodeVersion = getSystemNodeVersion(); + const usedNodeVersion = + SUPPORTED_NODE_VERSIONS.find((version) => version >= systemNodeVersion) ?? + SUPPORTED_NODE_VERSIONS.at(-1); + + const runtimeVersion = `nodejs${usedNodeVersion}.x`; const functionConfigPath = resolve( nitro.options.output.serverDir, ".vc-config.json"