Describe the bug
I set my build/esbuild target to something below ES2020 in order to support by target browser (~Safari 13, supports around ES2019, pre-ES2020). Then I can use newer syntax in .ts files just fine, but as soon as I use any new syntax in .vue SFC files (inside of <script lang="ts">, no matter if setup or not), I get errors, because it's not properly transpiled.
One example of such syntax is optional chaining operator, and as such adding a line like
will yield error like following:

Again, it works as expected if I use this inside of any .ts file, but fails inside of .vue.
Reproduction
https://github.com/p0358/vite-vue-transpilation-repro
Steps to reproduce
- Clone my repro repo (see commit to see what changes I had to made to default project, most importantly target)
- pnpm run dev
- Open in your latest browser, see all works
- Open in some older pre-ES2020 browser, see it fails and throws SyntaxError
- Change code in HelloWorld.vue to not include optional chaining anymore (change
?. to .)
- See that it now works in old browser too, and code from main.ts will print something into the console now, confirming the issue lies in improper transpilation of .vue files
Example old browser to test in: https://github.com/niutech/qt-ultralight-browser (note this one sadly has no dev tools, I can package a build based on the same browser with dev-tools if you want to test)
System Info
System:
OS: Windows 10 10.0.19045
CPU: (4) x64 Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz
Memory: 530.82 MB / 15.88 GB
Binaries:
Node: 19.1.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
npm: 8.19.3 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.19041.1266.0)
Internet Explorer: 11.0.19041.1566
npmPackages:
@vitejs/plugin-vue: ^3.2.0 => 3.2.0
vite: ^3.2.3 => 3.2.4
Used Package Manager
pnpm
Logs
SyntaxError: Unexpected token '.' — HelloWorld.vue
Validations
Describe the bug
I set my build/esbuild target to something below ES2020 in order to support by target browser (~Safari 13, supports around ES2019, pre-ES2020). Then I can use newer syntax in .ts files just fine, but as soon as I use any new syntax in .vue SFC files (inside of
<script lang="ts">, no matter ifsetupor not), I get errors, because it's not properly transpiled.One example of such syntax is optional chaining operator, and as such adding a line like
will yield error like following:

Again, it works as expected if I use this inside of any .ts file, but fails inside of .vue.
Reproduction
https://github.com/p0358/vite-vue-transpilation-repro
Steps to reproduce
?.to.)Example old browser to test in: https://github.com/niutech/qt-ultralight-browser (note this one sadly has no dev tools, I can package a build based on the same browser with dev-tools if you want to test)
System Info
System: OS: Windows 10 10.0.19045 CPU: (4) x64 Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz Memory: 530.82 MB / 15.88 GB Binaries: Node: 19.1.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD npm: 8.19.3 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Spartan (44.19041.1266.0) Internet Explorer: 11.0.19041.1566 npmPackages: @vitejs/plugin-vue: ^3.2.0 => 3.2.0 vite: ^3.2.3 => 3.2.4Used Package Manager
pnpm
Logs
Validations