Skip to content

Commit

Permalink
Avoid dynamic import feature detection
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jun 14, 2022
1 parent ef7d200 commit 2e3ad47
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/babel-core/src/config/files/module-types.ts
Expand Up @@ -3,16 +3,22 @@ import type { Handler } from "gensync";
import path from "path";
import { pathToFileURL } from "url";
import { createRequire } from "module";
import semver from "semver";

const require = createRequire(import.meta.url);

let import_;
try {
// Node < 13.3 doesn't support import() syntax.
// Old Node.js versions don't support import() syntax.
import_ = require("./import").default;
} catch {}

export const supportsESM = !!import_;
export const supportsESM = semver.satisfies(
process.versions.node,
// older versions, starting from 10, support the dynamic
// import syntax but always return a rejected promise.
"^12.17 || ^13.2",
);

export default function* loadCjsOrMjsDefault(
filepath: string,
Expand Down

0 comments on commit 2e3ad47

Please sign in to comment.