Skip to content

Commit 41c4658

Browse files
authored
fix(bundledDev): print build errors to the terminal when an HMR update fails (#23024)
1 parent 9af244f commit 41c4658

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎packages/vite/src/node/server/bundledDev.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ export class BundledDev {
140140
this._devEngine = await dev(rolldownOptions, outputOptions, {
141141
onHmrUpdates: (result) => {
142142
if (result instanceof Error) {
143+
this.environment.logger.error(
144+
colors.red(`✘ Build error: ${result.message}`),
145+
{
146+
error: result,
147+
},
148+
)
143149
// TODO: send to the specific client
144150
for (const client of this.clients.getAll()) {
145151
client.send({

‎playground/hmr-full-bundle-mode/__tests__/hmr-full-bundle-mode.spec.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { setTimeout } from 'node:timers/promises'
22
import { expect, test, onTestFinished } from 'vitest'
3-
import { addFile, browserLogs, editFile, isBuild, page, readFile } from '~utils'
3+
import {
4+
addFile,
5+
browserLogs,
6+
editFile,
7+
isBuild,
8+
page,
9+
readFile,
10+
serverLogs,
11+
} from '~utils'
412

513
const assetUrl = /asset-[\w-]+\.png/
614

@@ -80,10 +88,14 @@ if (isBuild) {
8088
// BUNDLED -> GENERATING_HMR_PATCH -> BUNDLED
8189
test('handle generate hmr patch error', async () => {
8290
await expect.poll(() => page.textContent('.hmr')).toBe('hello')
91+
const lastServerLogIndex = serverLogs.length
8392
editFile('hmr.js', (code) =>
8493
code.replace("const foo = 'hello'", "const foo = 'hello"),
8594
)
8695
await expect.poll(() => page.isVisible('vite-error-overlay')).toBe(true)
96+
await expect
97+
.poll(() => serverLogs.slice(lastServerLogIndex).join('\n'))
98+
.toContain('Build error')
8799

88100
editFile('hmr.js', (code) =>
89101
code.replace("const foo = 'hello", "const foo = 'hello'"),

0 commit comments

Comments
 (0)