From 297937ea31e8f9cfa2beee425bb33d593771d174 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Mon, 3 Jan 2022 11:00:59 -0500 Subject: [PATCH] fix(ssr): avoid rewriting error.message for "Server is closed" error --- packages/vite/src/node/ssr/ssrModuleLoader.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/ssr/ssrModuleLoader.ts b/packages/vite/src/node/ssr/ssrModuleLoader.ts index 21da9a38e933e3..df8bfe1a620628 100644 --- a/packages/vite/src/node/ssr/ssrModuleLoader.ts +++ b/packages/vite/src/node/ssr/ssrModuleLoader.ts @@ -24,6 +24,8 @@ const isDebug = !!process.env.DEBUG const debug = createDebugger('vite:ssr') const warn = (...msg: string[]) => debug(chalk.yellow('warn ') + msg.join(' ')) +const E_SERVER_CLOSED = 'Server is closed' + export type SSRModuleExports = Record export interface SSRModule { @@ -199,7 +201,7 @@ export async function ssrLoadModule( urlStack: string[] = [] ): Promise { if (server.closed) { - throw Error('Server is closed') + throw Error(E_SERVER_CLOSED) } if (Array.isArray(url)) { // Load multiple entries in parallel. @@ -237,7 +239,7 @@ export async function ssrLoadModule( )) ) executing.catch((e) => { - if (!e.originalStack) { + if (!e.originalStack && e.message !== E_SERVER_CLOSED) { try { ssrRewriteStacktrace(e, server.moduleGraph) } catch {}