File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed 
packages/vite-node/src/hmr Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -160,8 +160,8 @@ async function fetchUpdate(
160160  } 
161161} 
162162
163- function  warnFailedFetch ( err : Error ,  path : string  |  string [ ] )  { 
164-   if  ( ! err . message . match ( 'fetch' ) )  { 
163+ function  warnFailedFetch ( err : unknown ,  path : string  |  string [ ] )  { 
164+   if  ( ! ( err   instanceof   Error )   ||   ! err . message . match ( 'fetch' ) )  { 
165165    console . error ( err ) 
166166  } 
167167
Original file line number Diff line number Diff line change 1+ if  ( import . meta. hot )  { 
2+   import . meta. hot . accept ( ( )  =>  { } ) 
3+   if  ( import . meta. hot . data . value  ==  null )  { 
4+     import . meta. hot . data . value  =  0 
5+   } 
6+   else  { 
7+     // eslint-disable-next-line no-throw-literal 
8+     throw  'some error' 
9+   } 
10+ } 
11+ console . error ( 'ready' ) 
Original file line number Diff line number Diff line change @@ -15,3 +15,16 @@ test('hmr.accept works correctly', async () => {
1515  await  viteNode . waitForStderr ( 'Accept' ) 
1616  await  viteNode . waitForStdout ( `[vite-node] hot updated: ${ scriptFile }  ` ) 
1717} ) 
18+ 
19+ test ( 'can handle top-level throw in self-accepting module' ,  async  ( )  =>  { 
20+   const  scriptFile  =  resolve ( __dirname ,  '../src/hmr-throw.js' ) 
21+ 
22+   const  {  viteNode }  =  await  runViteNodeCli ( '--watch' ,  scriptFile ) 
23+ 
24+   await  viteNode . waitForStderr ( 'ready' ) 
25+ 
26+   editFile ( scriptFile ,  content  =>  `${ content }  \nconsole.error("done")` ) 
27+ 
28+   await  viteNode . waitForStderr ( 'some error' ) 
29+   await  viteNode . waitForStderr ( `[hmr] Failed to reload ${ scriptFile }  . This could be due to syntax errors or importing non-existent modules. (see errors above)` ) 
30+ } ) 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments