1
1
// @ts -check
2
2
3
+ const minimumNodeVersion = "20.11.0" ;
4
+
3
5
/**
4
6
* @typedef {import("@rescript/linux-x64") } BinaryModuleExports
5
7
*/
@@ -23,6 +25,9 @@ if (supportedPlatforms.includes(target)) {
23
25
try {
24
26
mod = await import ( binPackageName ) ;
25
27
} catch {
28
+ // First check if we are on an unsupported node version, as that may be the cause for the error.
29
+ checkNodeVersionSupported ( ) ;
30
+
26
31
throw new Error (
27
32
`Package ${ binPackageName } not found. Make sure the rescript package is installed correctly.` ,
28
33
) ;
@@ -43,3 +48,27 @@ export const {
43
48
rescript_exe,
44
49
} ,
45
50
} = mod ;
51
+
52
+ function checkNodeVersionSupported ( ) {
53
+ // Check for the minimum Node.js version first.
54
+ if (
55
+ typeof process !== "undefined" &&
56
+ process . versions != null &&
57
+ process . versions . node != null
58
+ ) {
59
+ const currentVersion = process . versions . node ;
60
+ const required = minimumNodeVersion . split ( "." ) . map ( Number ) ;
61
+ const current = currentVersion . split ( "." ) . map ( Number ) ;
62
+ if (
63
+ current [ 0 ] < required [ 0 ] ||
64
+ ( current [ 0 ] === required [ 0 ] && current [ 1 ] < required [ 1 ] ) ||
65
+ ( current [ 0 ] === required [ 0 ] &&
66
+ current [ 1 ] === required [ 1 ] &&
67
+ current [ 2 ] < required [ 2 ] )
68
+ ) {
69
+ throw new Error (
70
+ `ReScript requires Node.js >=${ minimumNodeVersion } , but found ${ currentVersion } .` ,
71
+ ) ;
72
+ }
73
+ }
74
+ }
0 commit comments