Skip to content

Commit

Permalink
esm: fix esm load bug
Browse files Browse the repository at this point in the history
Fixes: nodejs/node#25482

PR-URL: nodejs/node#25491
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
ZYSzys authored and aduh95 committed May 25, 2019
1 parent cda0d16 commit ef51e92
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,12 @@ Module.prototype.load = function(filename) {
const module = ESMLoader.moduleMap.get(url);
// create module entry at load time to snapshot exports correctly
const exports = this.exports;
if (module !== undefined) { // called from cjs translator
module.reflect.onReady((reflect) => {
reflect.exports.default.set(exports);
});
if (module !== undefined) { // Called from cjs translator
if (module.reflect) {
module.reflect.onReady((reflect) => {
reflect.exports.default.set(exports);
});
}
} else { // preemptively cache
ESMLoader.moduleMap.set(
url,
Expand Down

0 comments on commit ef51e92

Please sign in to comment.