@@ -211,7 +211,7 @@ class ESMLoader {
211211 return module ;
212212 } ;
213213 const job = new ModuleJob ( this , url , evalInstance , false , false ) ;
214- this . moduleMap . set ( url , job ) ;
214+ this . moduleMap . set ( url , job , undefined ) ;
215215 const { module } = await job . run ( ) ;
216216
217217 return {
@@ -222,11 +222,20 @@ class ESMLoader {
222222 async getModuleJob ( specifier , parentURL , import_assertions ) {
223223 const { format, url } = await this . resolve ( specifier , parentURL ) ;
224224
225- let job = this . moduleMap . get ( url ) ;
226- // CommonJS will set functions for lazy job evaluation.
227- if ( typeof job === 'function' ) this . moduleMap . set ( url , job = job ( ) ) ;
228-
229- if ( job !== undefined ) return job ;
225+ let job
226+ const jobMap = this . moduleMap . get ( url ) ;
227+
228+ if ( jobMap != null ) {
229+ // To avoid race conditions, always wait for non assertion job to fulfill
230+ if ( import_assertions . type != null ) await jobMap [ undefined ] ;
231+
232+ let job = jobMap [ import_assertions . type ] ;
233+
234+ // CommonJS will set functions for lazy job evaluation.
235+ if ( typeof job === 'function' ) this . moduleMap . set ( url , job = job ( ) , import_assertions . type ) ;
236+
237+ if ( job !== undefined ) return job ;
238+ }
230239
231240 const moduleProvider = async ( url , isMain ) => {
232241 const { format : finalFormat , source } = await this . load ( url , { format } ) ;
@@ -256,7 +265,7 @@ class ESMLoader {
256265 inspectBrk
257266 ) ;
258267
259- this . moduleMap . set ( url , job ) ;
268+ this . moduleMap . set ( url , job , import_assertions . type ) ;
260269
261270 return job ;
262271 }
0 commit comments