When using vite, the method decorator cannot be used (@watch for instance). The decorator appears “as is” in the js file sent to the browser in development mode (npm run dev) so the browser throws an error (illegal character U+0040) and at build time (npm run buildwhich executes tsc && vite build) rollup throws an error because @ is invalid. Class decorators (@inject) work well.
Using esbuild-plugin-tsc could be a solution but vite config file does not give any option to configure esbuild.
Aurelia is not responsible for that, but since there is a vite plugin is there a “recommended way” to make function decorators work ?
For the moment I use IObserverLocator instead of @watch but this kind of “Plan B” may not always be possible.
vite latest version (5.2.11) uses esbuild 0.20.2 while decorators are supported since esbuild 0.21.3 (Release v0.21.3 · evanw/esbuild · GitHub). Overriding the esbuild version in package.json should help but it does not.
esbuild has two ways to set the transform target: its target top-level option, and tsconfigRaw.compilerOptions.target option (from tsconfig.json). The former Vite sets as esnext and esbuild will prioritize that over tsconfigRaw."
For the moment, esbuild version has to be overridden in the package.json :
In Vite, method decorators like @watch aren’t functioning correctly due to how Vite handles decorators in development mode. A potential solution involves using esbuild-plugin-tsc to transpile TypeScript code with decorators properly. However, configuring this plugin within the Vite config file might be tricky. Exploring Vite plugins or community suggestions could help find a solution. As a temporary fix, consider using alternatives like IObserverLocator instead of @watch.