Add module-context-hook ESM support (#89)
* Add module-context-hook ESM support
* Undo styling
Co-authored-by: Alexandre Cai <100454395+alex-jungle-cat@users.noreply.github.com>
commit7d40edb7fc859334f562c9f24a34379d2ab35035
authorAlexandre <alexandre@repl.it>
dateFri 29 Apr 2022, 05:23 (4 years ago)
parent74f34a6
prybar_assets/nodejs/module-context-hook.js+9−1
@@ -193,7 +193,15 @@ function runModule(moduleName, isInteractive) {
193193 });
194194 }
195195
196− require(absPath);
196+ try {
197+ require(absPath);
198+ } catch (e) {
199+ if (e.code === 'ERR_REQUIRE_ESM') {
200+ import(absPath);
201+ } else {
202+ throw e;
203+ }
204+ }
197205}
198206
199207/**