Skip to content

Commit

Permalink
fix(build): build error message output twice (#15664)
Browse files Browse the repository at this point in the history
  • Loading branch information
btea authored Jan 23, 2024
1 parent b7c6629 commit 74382b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ export async function build(
},
}

const outputBuildError = (e: RollupError) => {
const mergeRollupError = (e: RollupError) => {
let msg = colors.red((e.plugin ? `[${e.plugin}] ` : '') + e.message)
if (e.id) {
msg += `\nfile: ${colors.cyan(
Expand All @@ -554,6 +554,11 @@ export async function build(
if (e.frame) {
msg += `\n` + colors.yellow(e.frame)
}
return msg
}

const outputBuildError = (e: RollupError) => {
const msg = mergeRollupError(e)
clearLine()
config.logger.error(msg, { error: e })
}
Expand Down Expand Up @@ -704,7 +709,8 @@ export async function build(
}
return Array.isArray(outputs) ? res : res[0]
} catch (e) {
outputBuildError(e)
e.message = mergeRollupError(e)
clearLine()
throw e
} finally {
if (bundle) await bundle.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '~utils'

const unexpectedTokenSyntaxErrorRE =
/^parsing .* failed: SyntaxError: Unexpected token.*\}.*/
/(\[vite:esbuild\] )*parsing .* failed: SyntaxError: Unexpected token.*\}.*/

describe.runIf(isBuild)('build', () => {
test('should throw an error on build', () => {
Expand Down

0 comments on commit 74382b9

Please sign in to comment.