@@ -3,7 +3,13 @@ import fsp from 'node:fs/promises'
33import path from 'node:path'
44import { performance } from 'node:perf_hooks'
55import glob from 'fast-glob'
6- import type { BuildContext, Loader, OnLoadResult, Plugin } from 'esbuild'
6+ import type {
7+ BuildContext,
8+ BuildOptions,
9+ Loader,
10+ OnLoadResult,
11+ Plugin,
12+ } from 'esbuild'
713import esbuild, { formatMessages, transform } from 'esbuild'
814import colors from 'picocolors'
915import type { ResolvedConfig } from '..'
@@ -224,16 +230,7 @@ async function prepareEsbuildScanner(
224230 logLevel: 'silent',
225231 plugins: [...plugins, plugin],
226232 tsconfig,
227- tsconfigRaw:
228- tsconfig || typeof tsconfigRaw === 'string'
229- ? tsconfigRaw
230- : {
231- ...tsconfigRaw,
232- compilerOptions: {
233- experimentalDecorators: true,
234- ...tsconfigRaw?.compilerOptions,
235- },
236- },
233+ tsconfigRaw: resolveTsconfigRaw(tsconfig, tsconfigRaw),
237234 ...esbuildOptions,
238235 })
239236}
@@ -666,3 +663,22 @@ function shouldExternalizeDep(resolvedId: string, rawId: string): boolean {
666663function isScannable(id: string): boolean {
667664 return JS_TYPES_RE.test(id) || htmlTypesRE.test(id)
668665}
666+
667+ // esbuild v0.18 only transforms decorators when `experimentalDecorators` is set to `true`.
668+ // To preserve compat with the esbuild breaking change, we set `experimentalDecorators` to
669+ // `true` by default if it's unset.
670+ // TODO: Remove this in Vite 5 and check https://github.com/vitejs/vite/pull/13805#issuecomment-1633612320
671+ export function resolveTsconfigRaw(
672+ tsconfig: string | undefined,
673+ tsconfigRaw: BuildOptions['tsconfigRaw'],
674+ ): BuildOptions['tsconfigRaw'] {
675+ return tsconfig || typeof tsconfigRaw === 'string'
676+ ? tsconfigRaw
677+ : {
678+ ...tsconfigRaw,
679+ compilerOptions: {
680+ experimentalDecorators: true,
681+ ...tsconfigRaw?.compilerOptions,
682+ },
683+ }
684+ }