diff --git a/lib/internal/loader/ModuleJob.js b/lib/internal/loader/ModuleJob.js index f79cc6cfe1d94a..b3553fc7235d95 100644 --- a/lib/internal/loader/ModuleJob.js +++ b/lib/internal/loader/ModuleJob.js @@ -50,10 +50,11 @@ class ModuleJob { } async instantiate() { - if (this.instantiated) { - return this.instantiated; + if (!this.instantiated) { + return this.instantiated = this._instantiate(); } - return this.instantiated = this._instantiate(); + await this.instantiated; + return this.module; } // This method instantiates the module associated with this job and its diff --git a/test/es-module/test-esm-cyclic-dynamic-import.mjs b/test/es-module/test-esm-cyclic-dynamic-import.mjs new file mode 100644 index 00000000000000..c8dfff919c2f7e --- /dev/null +++ b/test/es-module/test-esm-cyclic-dynamic-import.mjs @@ -0,0 +1,3 @@ +// Flags: --experimental-modules +import '../common'; +import('./test-esm-cyclic-dynamic-import');