Skip to content

Commit

Permalink
Better fix for old Node
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jan 6, 2022
1 parent 54225c5 commit 70db994
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/babel-core/src/config/files/import-meta-resolve.ts
Expand Up @@ -7,18 +7,22 @@ let import_;
try {
// Node < 13.3 doesn't support import() syntax.
import_ = require("./import").default;
} catch {}
} catch {
import_ = () => Promise.resolve({});
}

// import.meta.resolve is only available in ESM, but this file is compiled to CJS.
// We can extract ir using dynamic import.
const resolveP =
import_ && import_("data:text/javascript,export default import.meta.resolve");
let resolveP;

export default async function getImportMetaResolve(): Promise<
ImportMeta["resolve"]
> {
// import.meta.resolve is only available in ESM, but this file is compiled to CJS.
// We can extract it using dynamic import.
resolveP ??= import_(
"data:text/javascript,export default import.meta.resolve",
);
// Since import.meta.resolve is unstable and only available when
// using the --experimental-import-meta-resolve flag, we almost
// always use the polyfill for now.
return (resolveP && (await resolveP).default) || polyfill;
return (await resolveP).default || polyfill;
}

0 comments on commit 70db994

Please sign in to comment.