Skip to content

Commit 1fac9fa

Browse files
authored
Add node version check (#7723)
1 parent 0fff45a commit 1fac9fa

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
- Apply heuristic to suggest using JSX fragments where we guess that might be what the user wanted. https://github.com/rescript-lang/rescript/pull/7714
1818
- Show deprecation warnings for `bs-dependencies` etc. for local dependencies only. https://github.com/rescript-lang/rescript/pull/7724
19+
- Add check for minimum required node version. https://github.com/rescript-lang/rescript/pull/7723
1920

2021
#### :bug: Bug fix
2122

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)