Subscribe on changes!

`script setup` sometimes generate invalid code when using `defineEmit` and `defineProps`

avatar
Dec 6th 2020

Version

3.0.4

Reproduction link

https://github.com/leopiccionia/vue-script-setup-emit-repro

Steps to reproduce

Just run the repro, with npm run dev.

What is expected?

Compiler should generate valid code.

What is actually happening?

Code fails with syntax error.

The problem is in this line from output:

import { , ref } from '/@modules/vue.js'

The preceding comma is not valid in this place of import statement.

A workaround is changing the order of imports, so that defineEmit and defineProps are trailing.


I'm not sure if this is a Vite-specific error. I can move the issue, if needed.

avatar
Dec 6th 2020

I think that PR #2729 should be a fix.

avatar
Jan 28th 2021

I did not notice that https://github.com/vuejs/vue-next/issues/3088 is a duplicate of this issue, and I submitted a fix there. So I also linked my PR here, because there are some differences between my PR and https://github.com/vuejs/vue-next/pull/2729