@@ -3,7 +3,7 @@ import path from 'node:path';
33import { URL } from 'node:url' ;
44import colors from 'kleur' ;
55import sirv from 'sirv' ;
6- import { isCSSRequest , loadEnv } from 'vite' ;
6+ import { isCSSRequest , loadEnv , buildErrorMessage } from 'vite' ;
77import { getRequest , setResponse } from '../../../exports/node/index.js' ;
88import { installPolyfills } from '../../../exports/node/polyfills.js' ;
99import { coalesce_to_error } from '../../../utils/error.js' ;
@@ -50,11 +50,25 @@ export async function dev(vite, vite_config, svelte_config) {
5050 /** @type {Error | null } */
5151 let manifest_error = null ;
5252
53+ /** @param {string } url */
54+ async function loud_ssr_load_module ( url ) {
55+ try {
56+ return await vite . ssrLoadModule ( url ) ;
57+ } catch ( /** @type {any } */ err ) {
58+ const msg = buildErrorMessage ( err , [ colors . red ( `Internal server error: ${ err . message } ` ) ] ) ;
59+
60+ vite . config . logger . error ( msg , { error : err } ) ;
61+ vite . ws . send ( { type : 'error' , err : err } ) ;
62+
63+ throw err ;
64+ }
65+ }
66+
5367 /** @param {string } id */
5468 async function resolve ( id ) {
5569 const url = id . startsWith ( '..' ) ? `/@fs${ path . posix . resolve ( id ) } ` : `/${ id } ` ;
5670
57- const module = await vite . ssrLoadModule ( url ) ;
71+ const module = await loud_ssr_load_module ( url ) ;
5872
5973 const module_node = await vite . moduleGraph . getModuleByUrl ( url ) ;
6074 if ( ! module_node ) throw new Error ( `Could not find node for ${ url } ` ) ;
@@ -161,7 +175,7 @@ export async function dev(vite, vite_config, svelte_config) {
161175 ( query . has ( 'svelte' ) && query . get ( 'type' ) === 'style' )
162176 ) {
163177 try {
164- const mod = await vite . ssrLoadModule ( dep . url ) ;
178+ const mod = await loud_ssr_load_module ( dep . url ) ;
165179 styles [ dep . url ] = mod . default ;
166180 } catch {
167181 // this can happen with dynamically imported modules, I think
@@ -191,7 +205,7 @@ export async function dev(vite, vite_config, svelte_config) {
191205 endpoint : endpoint
192206 ? async ( ) => {
193207 const url = path . resolve ( cwd , endpoint . file ) ;
194- return await vite . ssrLoadModule ( url ) ;
208+ return await loud_ssr_load_module ( url ) ;
195209 }
196210 : null ,
197211 endpoint_id : endpoint ?. file
0 commit comments