@@ -10,13 +10,28 @@ import type {
10
10
VercelServerlessFunctionConfig ,
11
11
} from "./types" ;
12
12
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
+
13
24
export async function generateFunctionFiles ( nitro : Nitro ) {
14
25
const buildConfigPath = resolve ( nitro . options . output . dir , "config.json" ) ;
15
26
const buildConfig = generateBuildConfig ( nitro ) ;
16
27
await writeFile ( buildConfigPath , JSON . stringify ( buildConfig , null , 2 ) ) ;
17
28
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` ;
20
35
const functionConfigPath = resolve (
21
36
nitro . options . output . serverDir ,
22
37
".vc-config.json"
0 commit comments