vitejs / vite-plugin-vue2

Vite plugin for Vue 2.7
MIT License
551 stars 48 forks source link

Plugin fails when parsing .vue-file without <template> #15

Closed johannes-z closed 2 years ago

johannes-z commented 2 years ago

There is already an open pull request: #11


I have several Components in my project that use render functions, but are defined as .vue to allow using <style> tags. This plugin fails if no <template> is specified.

[vite] Internal server error: Cannot read properties of null (reading 'lang'

The error stems from this LOC: https://github.com/vitejs/vite-plugin-vue2/blob/e68672807359e36a5bec647dcf21a6b3b1580c70/src/main.ts#L182 (template is undefined).

This if should also check for an undefined template.

Repro: https://github.com/johannes-z/repro_vite-plugin-vue2-templates

Works

<template>
  <div>
    <!-- dummy -->
  </div>
</template>

<script lang="ts">
import Vue, { h, defineComponent } from 'vue'
export default defineComponent({
  setup() {
    return () => h('div', 'Test')
  }
})
</script>

Doesn't Work

<script lang="ts">
import Vue, { h, defineComponent } from 'vue'
export default defineComponent({
  setup() {
    return () => h('div', 'Test')
  }
})
</script>