Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

fix: always fallback to import() if require() fails (#5384)

Marcelo Shima295c168628c2
diff --git a/lib/nodejs/esm-utils.js b/lib/nodejs/esm-utils.js
index 6c43d4cc..3cea8af2 100644
--- a/lib/nodejs/esm-utils.js
+++ b/lib/nodejs/esm-utils.js
@@ -93,13 +93,8 @@ const requireModule = async (file, esmDecorator) => {
try {
return require(file);
} catch (err) {
- if (
- err.code === 'ERR_REQUIRE_ASYNC_MODULE'
- ) {
- // Import if the module is async.
- return formattedImport(file, esmDecorator);
- }
- throw err;
+ // Import if require fails.
+ return dealWithExports(await formattedImport(file, esmDecorator));
}
}