File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -180,11 +180,12 @@ export class ViteNodeRunner {
180180 const  promise  =  this . directRequest ( id ,  fsPath ,  callstack ) 
181181 Object . assign ( mod ,  {  promise,  evaluated : false  } ) 
182182
183-  promise . finally ( ( )  =>  { 
183+  try  { 
184+  return  await  promise 
185+  } 
186+  finally  { 
184187 mod . evaluated  =  true 
185-  } ) 
186- 
187-  return  await  promise 
188+  } 
188189 } 
189190
190191 /** @internal  */ 
@@ -272,7 +273,7 @@ export class ViteNodeRunner {
272273 throw  new  Error ( `[vite-node] Failed to load ${ id }  ) 
273274
274275 const  file  =  cleanUrl ( resolvedId  ||  fsPath ) 
275-   // console.log('file', file) 
276+ 
276277 // disambiguate the `<UNIT>:/` on windows: see nodejs/node#31710 
277278 const  url  =  pathToFileURL ( file ) . href 
278279 const  meta  =  {  url } 
Original file line number Diff line number Diff line change @@ -53,3 +53,11 @@ test('dynamic import has null prototype', async () => {
5353
5454 expect ( Object . getPrototypeOf ( stringTimeoutMod ) ) . toBe ( null ) 
5555} ) 
56+ 
57+ test ( 'dynamic import throws an error' ,  async  ( )  =>  { 
58+  const  path  =  './some-unknown-path' 
59+  const  imported  =  import ( path ) 
60+  await  expect ( imported ) . rejects . toThrowError ( / F a i l e d   t o   l o a d / ) 
61+  // @ts -expect-error path does not exist 
62+  await  expect ( ( )  =>  import ( './some-unknown-path' ) ) . rejects . toThrowError ( / F a i l e d   t o   l o a d / ) 
63+ } ) 
                         You can’t perform that action at this time. 
           
                  
0 commit comments