Skip to content

Commit 174a192

Browse files
authored
use import() if ERR_REQUIRE_ASYNC_MODULE
- supports node v22.12.0 and later when using top level await
1 parent e422eb1 commit 174a192

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/shared/require-or-import.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ function requireOrImport(path, callback) {
2323
if (pathToFileURL && importESM) {
2424
// Because e.code is undefined on nyc process.
2525
/* istanbul ignore else */
26-
if (e.code === 'ERR_REQUIRE_ESM' || process.env.NYC_CONFIG) {
26+
// Check 'ERR_REQUIRE_ASYNC_MODULE' if on node v22.12.0 or later to allow importing from files using top level await.
27+
if (e.code === 'ERR_REQUIRE_ESM' || process.env.NYC_CONFIG || e.code === 'ERR_REQUIRE_ASYNC_MODULE') {
2728
// This is needed on Windows, because import() fails if providing a Windows file path.
2829
var url = pathToFileURL(path);
2930
importESM(url).then(function(esm) { callback(null, esm); }, callback);

0 commit comments

Comments
 (0)