From 554f45f4d820c57c0874ebe48ef2fddfafdd0750 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 26 Nov 2024 17:29:08 +0900 Subject: [PATCH] fix: display pre-transform error details (#18764) --- packages/vite/src/node/server/environment.ts | 12 ++++++++---- packages/vite/src/node/server/index.ts | 13 ++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/vite/src/node/server/environment.ts b/packages/vite/src/node/server/environment.ts index 39e363931d93c4..6b126122ee65dc 100644 --- a/packages/vite/src/node/server/environment.ts +++ b/packages/vite/src/node/server/environment.ts @@ -35,6 +35,7 @@ import { } from './pluginContainer' import { type WebSocketServer, isWebSocketServer } from './ws' import { warmupFiles } from './warmup' +import { buildErrorMessage } from './middlewares/error' export interface DevEnvironmentContext { hot: boolean @@ -220,10 +221,13 @@ export class DevEnvironment extends BaseEnvironment { return } // Unexpected error, log the issue but avoid an unhandled exception - this.logger.error(`Pre-transform error: ${e.message}`, { - error: e, - timestamp: true, - }) + this.logger.error( + buildErrorMessage(e, [`Pre-transform error: ${e.message}`], false), + { + error: e, + timestamp: true, + }, + ) } } diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index f8fb4386d89dfc..380e0a83f6573b 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -80,7 +80,7 @@ import { timeMiddleware } from './middlewares/time' import { ModuleGraph } from './mixedModuleGraph' import type { ModuleNode } from './mixedModuleGraph' import { notFoundMiddleware } from './middlewares/notFound' -import { errorMiddleware } from './middlewares/error' +import { buildErrorMessage, errorMiddleware } from './middlewares/error' import type { HmrOptions, HotBroadcaster } from './hmr' import { createDeprecatedHotBroadcaster, @@ -569,10 +569,13 @@ export async function _createServer( return } // Unexpected error, log the issue but avoid an unhandled exception - server.config.logger.error(`Pre-transform error: ${e.message}`, { - error: e, - timestamp: true, - }) + server.config.logger.error( + buildErrorMessage(e, [`Pre-transform error: ${e.message}`], false), + { + error: e, + timestamp: true, + }, + ) } }, transformIndexHtml(url, html, originalUrl) {