vite-plugin-vue icon indicating copy to clipboard operation
vite-plugin-vue copied to clipboard

Dev server does not transpile script in .vue files (but it works in .ts ones)

Open p0358 opened this issue 1 year ago • 8 comments

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

test()?.value || 'bb'

will yield error like following: image

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

  1. Clone my repro repo (see commit to see what changes I had to made to default project, most importantly target)
  2. pnpm run dev
  3. Open in your latest browser, see all works
  4. Open in some older pre-ES2020 browser, see it fails and throws SyntaxError
  5. Change code in HelloWorld.vue to not include optional chaining anymore (change ?. to .)
  6. 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

p0358 avatar Dec 01 '22 14:12 p0358