Skip to content

Commit 295c168

Browse files
fix: always fallback to import() if require() fails (#5384)
* always fallback to import if requiring esm module fails * Update lib/nodejs/esm-utils.js Co-authored-by: Josh Goldberg ✨ <[email protected]> --------- Co-authored-by: Josh Goldberg ✨ <[email protected]>
1 parent 5d617f3 commit 295c168

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

lib/nodejs/esm-utils.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,8 @@ const requireModule = async (file, esmDecorator) => {
9393
try {
9494
return require(file);
9595
} catch (err) {
96-
if (
97-
err.code === 'ERR_REQUIRE_ASYNC_MODULE'
98-
) {
99-
// Import if the module is async.
100-
return formattedImport(file, esmDecorator);
101-
}
102-
throw err;
96+
// Import if require fails.
97+
return dealWithExports(await formattedImport(file, esmDecorator));
10398
}
10499
}
105100

0 commit comments

Comments
 (0)