Skip to content

Commit 234766e

Browse files
committed
Add node version check
1 parent 0fff45a commit 234766e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

cli/common/bins.js

Lines changed: 28 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,26 @@ export const {
4348
rescript_exe,
4449
},
4550
} = mod;
51+
52+
function checkNodeVersionSupported() {
53+
if (
54+
typeof process !== "undefined" &&
55+
process.versions != null &&
56+
process.versions.node != null
57+
) {
58+
const currentVersion = process.versions.node;
59+
const required = minimumNodeVersion.split(".").map(Number);
60+
const current = currentVersion.split(".").map(Number);
61+
if (
62+
current[0] < required[0] ||
63+
(current[0] === required[0] && current[1] < required[1]) ||
64+
(current[0] === required[0] &&
65+
current[1] === required[1] &&
66+
current[2] < required[2])
67+
) {
68+
throw new Error(
69+
`ReScript requires Node.js >=${minimumNodeVersion}, but found ${currentVersion}.`,
70+
);
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)