Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

- 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
- Show deprecation warnings for `bs-dependencies` etc. for local dependencies only. https://github.com/rescript-lang/rescript/pull/7724
- Add check for minimum required node version. https://github.com/rescript-lang/rescript/pull/7723

#### :bug: Bug fix

Expand Down
28 changes: 28 additions & 0 deletions cli/common/bins.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @ts-check

const minimumNodeVersion = "20.11.0";

/**
* @typedef {import("@rescript/linux-x64")} BinaryModuleExports
*/
Expand All @@ -23,6 +25,9 @@ if (supportedPlatforms.includes(target)) {
try {
mod = await import(binPackageName);
} catch {
// First check if we are on an unsupported node version, as that may be the cause for the error.
checkNodeVersionSupported();

throw new Error(
`Package ${binPackageName} not found. Make sure the rescript package is installed correctly.`,
);
Expand All @@ -43,3 +48,26 @@ export const {
rescript_exe,
},
} = mod;

function checkNodeVersionSupported() {
if (
typeof process !== "undefined" &&
process.versions != null &&
process.versions.node != null
) {
const currentVersion = process.versions.node;
const required = minimumNodeVersion.split(".").map(Number);
const current = currentVersion.split(".").map(Number);
if (
current[0] < required[0] ||
(current[0] === required[0] && current[1] < required[1]) ||
(current[0] === required[0] &&
current[1] === required[1] &&
current[2] < required[2])
) {
throw new Error(
`ReScript requires Node.js >=${minimumNodeVersion}, but found ${currentVersion}.`,
);
}
}
}