Skip to content

Commit bedfcfa

Browse files
authored
fix: code frame was not generated for postcss errors (#14986)
1 parent 2b4e793 commit bedfcfa

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

packages/vite/src/node/plugins/css.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,12 +1191,12 @@ async function compileCSS(
11911191
code,
11921192
{
11931193
line: warning.line,
1194-
column: warning.column,
1194+
column: warning.column - 1, // 1-based
11951195
},
11961196
warning.endLine !== undefined && warning.endColumn !== undefined
11971197
? {
11981198
line: warning.endLine,
1199-
column: warning.endColumn,
1199+
column: warning.endColumn - 1, // 1-based
12001200
}
12011201
: undefined,
12021202
)}`
@@ -1207,8 +1207,9 @@ async function compileCSS(
12071207
e.message = `[postcss] ${e.message}`
12081208
e.code = code
12091209
e.loc = {
1210-
column: e.column,
1210+
file: e.file,
12111211
line: e.line,
1212+
column: e.column - 1, // 1-based
12121213
}
12131214
throw e
12141215
}

packages/vite/src/node/server/pluginContainer.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ import { TraceMap, originalPositionFor } from '@jridgewell/trace-mapping'
6262
import MagicString from 'magic-string'
6363
import type { FSWatcher } from 'chokidar'
6464
import colors from 'picocolors'
65-
import type * as postcss from 'postcss'
6665
import type { Plugin } from '../plugin'
6766
import {
6867
cleanUrl,
@@ -429,15 +428,10 @@ export async function createPluginContainer(
429428
position: number | { column: number; line: number } | undefined,
430429
ctx: Context,
431430
) {
432-
const err = (
433-
typeof e === 'string' ? new Error(e) : e
434-
) as postcss.CssSyntaxError & RollupError
431+
const err = (typeof e === 'string' ? new Error(e) : e) as RollupError
435432
if (err.pluginCode) {
436433
return err // The plugin likely called `this.error`
437434
}
438-
if (err.file && err.name === 'CssSyntaxError') {
439-
err.id = normalizePath(err.file)
440-
}
441435
if (ctx._activePlugin) err.plugin = ctx._activePlugin.name
442436
if (ctx._activeId && !err.id) err.id = ctx._activeId
443437
if (ctx._activeCode) {
@@ -483,7 +477,7 @@ export async function createPluginContainer(
483477
line: (err as any).line,
484478
column: (err as any).column,
485479
}
486-
err.frame = err.frame || generateCodeFrame(err.id!, err.loc)
480+
err.frame = err.frame || generateCodeFrame(ctx._activeCode, err.loc)
487481
}
488482

489483
if (

0 commit comments

Comments
 (0)