From 709c291c5f408b824da60a7e1332c190586b5090 Mon Sep 17 00:00:00 2001 From: Karl von Randow Date: Sat, 18 Jan 2025 10:52:33 +1300 Subject: [PATCH] feat: use loc.file from rollup errors if available The loc.file references the file where the error occurred (containing the displayed line and column), rather than e.id which is the module. --- packages/vite/src/node/build.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index ea19a35d95bf55..ccc953c010043c 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -635,7 +635,12 @@ async function buildEnvironment( const stackOnly = extractStack(e) let msg = colors.red((e.plugin ? `[${e.plugin}] ` : '') + e.message) - if (e.id) { + if (e.loc && e.loc.file && e.loc.file !== e.id) { + msg += `\nfile: ${colors.cyan( + `${e.loc.file}:${e.loc.line}:${e.loc.column}` + + (e.id ? ` (${e.id})` : ''), + )}` + } else if (e.id) { msg += `\nfile: ${colors.cyan( e.id + (e.loc ? `:${e.loc.line}:${e.loc.column}` : ''), )}`