Skip to content

Commit

Permalink
fix: #5
Browse files Browse the repository at this point in the history
  • Loading branch information
nitedani committed Aug 7, 2024
1 parent ff48276 commit d0a1187
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/vike-node/src/plugin/plugins/devServerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function devServerPlugin(): Plugin {
globalStore.viteDevServer = vite
globalStore.setupHMRProxy = setupHMRProxy
patchViteServer(vite)
setupErrorHandler(vite)
initializeServerEntry(vite)
}
}
Expand Down Expand Up @@ -112,6 +113,27 @@ export function devServerPlugin(): Plugin {
}
}

function setupErrorHandler(vite: ViteDevServer) {
const _prepareStackTrace = Error.prepareStackTrace
Error.prepareStackTrace = function prepareStackTrace(error, stack) {
let ret = _prepareStackTrace?.(error, stack)
try {
ret = vite.ssrRewriteStacktrace(ret)
} catch (e) {
console.warn('Failed to apply Vite SSR stack trace fix:', e)
}
return ret
}

function onError(err: unknown) {
console.error(err)
logViteInfo('Server crash: Update a server file or type "r+enter" to restart the server.')
}

process.on('unhandledRejection', onError)
process.on('uncaughtException', onError)
}

async function setupReloader() {
const isReloaderSetup = process.env.VIKE_NODE_RELOADER_SETUP === 'true'
if (!isReloaderSetup) {
Expand Down

0 comments on commit d0a1187

Please sign in to comment.