fix astro esm-cjs entrypoint (#1300)

This commit is contained in:
Fred K. Schott 2021-09-03 10:46:36 -07:00 committed by GitHub
parent 7cb31c6e01
commit ac2c00e99b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix astro bin bug in some pre-ESM versions of Node v14.x

View file

@ -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