Skip to content

Commit

Permalink
feat: use loc.file from rollup errors if available
Browse files Browse the repository at this point in the history
The loc.file references the file where the error occurred (containing the displayed line and column), rather than e.id which is the module.
  • Loading branch information
karlvr committed Jan 19, 2025
1 parent 4f5845a commit 709c291
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}` : ''),
)}`
Expand Down

0 comments on commit 709c291

Please sign in to comment.