Skip to content

Commit dfa7c22

Browse files
committed
Add node version check
1 parent c79b033 commit dfa7c22

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

cli/common/bins.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// @ts-check
22

3+
const minimumNodeVersion = "20.11.0";
4+
35
/**
46
* @typedef {import("@rescript/linux-x64")} BinaryModuleExports
57
*/
@@ -23,6 +25,9 @@ if (supportedPlatforms.includes(target)) {
2325
try {
2426
mod = await import(binPackageName);
2527
} catch {
28+
// First check if we are on an unsupported node version, as that may be the cause for the error.
29+
checkNodeVersionSupported();
30+
2631
throw new Error(
2732
`Package ${binPackageName} not found. Make sure the rescript package is installed correctly.`,
2833
);
@@ -43,3 +48,27 @@ export const {
4348
rescript_exe,
4449
},
4550
} = 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

Comments
 (0)