We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e422eb1 commit 174a192Copy full SHA for 174a192
lib/shared/require-or-import.js
@@ -23,7 +23,8 @@ function requireOrImport(path, callback) {
23
if (pathToFileURL && importESM) {
24
// Because e.code is undefined on nyc process.
25
/* istanbul ignore else */
26
- 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.
27
+ if (e.code === 'ERR_REQUIRE_ESM' || process.env.NYC_CONFIG || e.code === 'ERR_REQUIRE_ASYNC_MODULE') {
28
// This is needed on Windows, because import() fails if providing a Windows file path.
29
var url = pathToFileURL(path);
30
importESM(url).then(function(esm) { callback(null, esm); }, callback);
0 commit comments