diff --git a/cli/template/base/next.config.mjs b/cli/template/base/next.config.mjs index 61964ea730..5254e0dfc3 100644 --- a/cli/template/base/next.config.mjs +++ b/cli/template/base/next.config.mjs @@ -4,6 +4,8 @@ */ await import("./src/env.mjs"); +checkNodeVersion(); + /** @type {import("next").NextConfig} */ const config = { reactStrictMode: true, @@ -20,3 +22,14 @@ const config = { }; export default config; + +function checkNodeVersion() { + const nodeVersion = process.versions.node; + const [major, minor] = nodeVersion.split(".").map((n) => parseInt(n)); + if (!major || !minor) { + throw new Error(`Unable to parse Node version: ${nodeVersion}`); + } + if (major < 18 || (major === 18 && minor < 6) || (major === 19 && minor < 7)) { + throw new Error(`You are running an outdated Node version. Please use at least 18.16, 19.7, or 20.0`); + } +} diff --git a/cli/template/extras/config/next-config-appdir.mjs b/cli/template/extras/config/next-config-appdir.mjs index 0914d3133e..31f2b89ce8 100644 --- a/cli/template/extras/config/next-config-appdir.mjs +++ b/cli/template/extras/config/next-config-appdir.mjs @@ -4,7 +4,20 @@ */ await import("./src/env.mjs"); +checkNodeVersion(); + /** @type {import("next").NextConfig} */ const config = {}; export default config; + +function checkNodeVersion() { + const nodeVersion = process.versions.node; + const [major, minor] = nodeVersion.split(".").map((n) => parseInt(n)); + if (!major || !minor) { + throw new Error(`Unable to parse Node version: ${nodeVersion}`); + } + if (major < 18 || (major === 18 && minor < 6) || (major === 19 && minor < 7)) { + throw new Error(`You are running an outdated Node version. Please use at least 18.16, 19.7, or 20.0`); + } +}