From 819a647d8f91161698856578b70b320b0e0569e8 Mon Sep 17 00:00:00 2001 From: ZYSzys Date: Mon, 13 May 2019 17:37:34 +0800 Subject: [PATCH] esm: fix esm load bug Fixes: https://github.com/nodejs/node/issues/25482 Backport-PR-URL: https://github.com/nodejs/node/pull/27874 PR-URL: https://github.com/nodejs/node/pull/25491 Reviewed-By: Guy Bedford Reviewed-By: James M Snell Reviewed-By: Rich Trott --- lib/internal/modules/cjs/loader.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 7b67efac2390e8..44c35718735426 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -661,9 +661,11 @@ Module.prototype.load = function(filename) { // 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.reflect) { + module.reflect.onReady((reflect) => { + reflect.exports.default.set(exports); + }); + } } else { // preemptively cache ESMLoader.moduleMap.set( url,