Skip to content

Commit 61aec65

Browse files
committed
fix(error-handling): avoid serilaizing unnecessary error properties when seinding to client
fix #1373
1 parent 1046fe0 commit 61aec65

File tree

1 file changed

+9
-3
lines changed
  • packages/vite/src/node/server/middlewares

1 file changed

+9
-3
lines changed

packages/vite/src/node/server/middlewares/error.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ import { ViteDevServer } from '../..'
44
import { Connect } from 'types/connect'
55
import { pad } from '../../utils'
66
import strip from 'strip-ansi'
7+
import { ErrorPayload } from 'types/hmrPayload'
78

8-
export function prepareError(err: Error | RollupError) {
9+
export function prepareError(err: Error | RollupError): ErrorPayload['err'] {
10+
// only copy the information we need and avoid serializing unnecessary
11+
// properties, since some errors may attach full objects (e.g. PostCSS)
912
return {
10-
...err,
1113
message: strip(err.message),
1214
stack: strip(err.stack || ''),
13-
frame: strip((err as RollupError).frame || '')
15+
id: (err as RollupError).id,
16+
frame: strip((err as RollupError).frame || ''),
17+
plugin: (err as RollupError).plugin,
18+
pluginCode: (err as RollupError).pluginCode,
19+
loc: (err as RollupError).loc
1420
}
1521
}
1622

0 commit comments

Comments
 (0)