From ac2c00e99b0fb9a85a95442fcc52800dc5201fcb Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Fri, 3 Sep 2021 10:46:36 -0700 Subject: [PATCH] fix astro esm-cjs entrypoint (#1300) --- .changeset/silver-icons-hope.md | 5 +++++ packages/astro/astro.js | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .changeset/silver-icons-hope.md diff --git a/.changeset/silver-icons-hope.md b/.changeset/silver-icons-hope.md new file mode 100644 index 000000000..76c43d04b --- /dev/null +++ b/.changeset/silver-icons-hope.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix astro bin bug in some pre-ESM versions of Node v14.x diff --git a/packages/astro/astro.js b/packages/astro/astro.js index d0b5a3f5f..c5dec5f66 100755 --- a/packages/astro/astro.js +++ b/packages/astro/astro.js @@ -37,12 +37,22 @@ async function main() { }); } + const version = process.versions.node; + + // Not supported (incomplete ESM): It's very difficult (impossible?) to load the + // dependencies below in an unknown module type. If `require` is undefined, then this file + // actually was run as ESM but one of the ESM preflight checks above failed. In that case, + // it's okay to hard-code the valid Node versions here since they will not change over time. + if (typeof require === 'undefined') { + console.error(`\nNode.js v${version} is not supported by Astro! +Please upgrade to a version of Node.js with complete ESM support: "^12.20.0 || ^14.13.1 || >=16.0.0"\n`); + } + // Not supported: Report the most helpful error message possible. const pkg = require('./package.json'); const ci = require('ci-info'); const semver = require('semver'); const engines = pkg.engines.node; - const version = process.versions.node; // TODO: Remove "semver" in Astro v1.0: This is mainly just to check our work. Once run in // the wild for a bit without error, we can assume our engine range is correct and won't