diff --git a/lib/shared/require-or-import.js b/lib/shared/require-or-import.js index 4cf5877e..af98aac5 100644 --- a/lib/shared/require-or-import.js +++ b/lib/shared/require-or-import.js @@ -23,7 +23,8 @@ function requireOrImport(path, callback) { if (pathToFileURL && importESM) { // Because e.code is undefined on nyc process. /* istanbul ignore else */ - if (e.code === 'ERR_REQUIRE_ESM' || process.env.NYC_CONFIG) { + // Check 'ERR_REQUIRE_ASYNC_MODULE' if on node v22.12.0 or later to allow importing from files using top level await. + if (e.code === 'ERR_REQUIRE_ESM' || process.env.NYC_CONFIG || e.code === 'ERR_REQUIRE_ASYNC_MODULE') { // This is needed on Windows, because import() fails if providing a Windows file path. var url = pathToFileURL(path); importESM(url).then(function(esm) { callback(null, esm); }, callback);