Skip to content

Commit eb8a9f2

Browse files
committed
fix(vercel): clamp runtime config to valid node versions (#2819)
1 parent e3a2d6f commit eb8a9f2

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/presets/vercel/utils.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,28 @@ import type {
1010
VercelServerlessFunctionConfig,
1111
} from "./types";
1212

13+
// https://vercel.com/docs/functions/runtimes/node-js/node-js-versions
14+
const SUPPORTED_NODE_VERSIONS = [16, 18, 20, 22];
15+
16+
function getSystemNodeVersion() {
17+
const systemNodeVersion = Number.parseInt(
18+
process.versions.node.split(".")[0]
19+
);
20+
21+
return Number.isNaN(systemNodeVersion) ? 20 : systemNodeVersion;
22+
}
23+
1324
export async function generateFunctionFiles(nitro: Nitro) {
1425
const buildConfigPath = resolve(nitro.options.output.dir, "config.json");
1526
const buildConfig = generateBuildConfig(nitro);
1627
await writeFile(buildConfigPath, JSON.stringify(buildConfig, null, 2));
1728

18-
const systemNodeVersion = process.versions.node.split(".")[0];
19-
const runtimeVersion = `nodejs${systemNodeVersion}.x`;
29+
const systemNodeVersion = getSystemNodeVersion();
30+
const usedNodeVersion =
31+
SUPPORTED_NODE_VERSIONS.find((version) => version >= systemNodeVersion) ??
32+
SUPPORTED_NODE_VERSIONS.at(-1);
33+
34+
const runtimeVersion = `nodejs${usedNodeVersion}.x`;
2035
const functionConfigPath = resolve(
2136
nitro.options.output.serverDir,
2237
".vc-config.json"

0 commit comments

Comments
 (0)