Skip to content

Commit d17cfed

Browse files
Copilotsapphi-redbluwy
authored
feat(optimizer): improve dependency optimization error messages with esbuild formatMessages (vitejs#20525)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: sapphi-red <[email protected]> Co-authored-by: bluwy <[email protected]>
1 parent c5a10ec commit d17cfed

File tree

1 file changed

+14
-2
lines changed
  • packages/vite/src/node/optimizer

1 file changed

+14
-2
lines changed

packages/vite/src/node/optimizer/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { promisify } from 'node:util'
55
import { performance } from 'node:perf_hooks'
66
import colors from 'picocolors'
77
import type { BuildContext, BuildOptions as EsbuildBuildOptions } from 'esbuild'
8-
import esbuild, { build } from 'esbuild'
8+
import esbuild, { build, formatMessages } from 'esbuild'
99
import { init, parse } from 'es-module-lexer'
1010
import { isDynamicPattern } from 'tinyglobby'
1111
import type { ResolvedConfig } from '../config'
@@ -724,12 +724,24 @@ export function runOptimizeDeps(
724724
return successfulResult
725725
})
726726

727-
.catch((e) => {
727+
.catch(async (e) => {
728728
if (e.errors && e.message.includes('The build was canceled')) {
729729
// esbuild logs an error when cancelling, but this is expected so
730730
// return an empty result instead
731731
return cancelledResult
732732
}
733+
const prependMessage = colors.red(
734+
'Error during dependency optimization:\n\n',
735+
)
736+
if (e.errors) {
737+
const msgs = await formatMessages(e.errors, {
738+
kind: 'error',
739+
color: true,
740+
})
741+
e.message = prependMessage + msgs.join('\n')
742+
} else {
743+
e.message = prependMessage + e.message
744+
}
733745
throw e
734746
})
735747
.finally(() => {

0 commit comments

Comments
 (0)