Skip to content

Commit

Permalink
Rethrow error if not ESM import error (lukeed#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
karlhorky authored Dec 17, 2023
1 parent 0cf486e commit 352f724
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ exports.load = async function (id) {
let m = await Function('x', 'return import(x)')(href);
return m.default || m; // interop
} catch (e) {
// Rethrow error if it is not any of:
// - not found error
// - old Node.js compatibility error
if (e && e.message && !e.code === 'ERR_MODULE_NOT_FOUND' &&
!['Not supported', 'require(...).pathToFileURL is not a function'].includes(e.message)
) throw e;
return require(id);
}
}
Expand Down

0 comments on commit 352f724

Please sign in to comment.