summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Fred K. Schott <fkschott@gmail.com> 2021-09-03 10:46:36 -0700
committerGravatar GitHub <noreply@github.com> 2021-09-03 17:46:36 +0000
commitac2c00e99b0fb9a85a95442fcc52800dc5201fcb (patch)
tree4758d52142945b94a47db9b996c0420bc7e3bef3
parent7cb31c6e019d58a639f8a645977753132ceb9e3e (diff)
downloadastro-ac2c00e99b0fb9a85a95442fcc52800dc5201fcb.tar.gz
astro-ac2c00e99b0fb9a85a95442fcc52800dc5201fcb.tar.zst
astro-ac2c00e99b0fb9a85a95442fcc52800dc5201fcb.zip
fix astro esm-cjs entrypoint (#1300)
-rw-r--r--.changeset/silver-icons-hope.md5
-rwxr-xr-xpackages/astro/astro.js12
2 files changed, 16 insertions, 1 deletions
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