underfin / vite-plugin-vue2

Vue2 plugin for Vite
621 stars 84 forks source link

bug: can't contain text `<script>` in JS #131

Closed privatenumber closed 3 years ago

privatenumber commented 3 years ago

SFC like this breaks:

<script lang="ts">
import { defineComponent } from 'vue-demi';

export default defineComponent({
    setup() {
        return {
            code: '<script></script>',
        }
    }
});
</script>

with error:

6:09:23 PM [vite] Internal server error: Transform failed with 1 error:
/web/src/views/Installation.vue:13:18: error: Unterminated string literal
  Plugin: vite-plugin-vue2
  File: /web/src/views/Installation.vue

  Unterminated string literal
  11 |      setup() {
  12 |          return {
  13 |              code: '<script>
     |                    ^

      at failureErrorWithLog (/web/node_modules/esbuild/lib/main.js:1451:15)
      at /web/node_modules/esbuild/lib/main.js:1262:29
      at /web/node_modules/esbuild/lib/main.js:609:9
      at handleIncomingPacket (/web/node_modules/esbuild/lib/main.js:706:9)
      at Socket.readFromStdout (/web/node_modules/esbuild/lib/main.js:576:7)
      at Socket.emit (events.js:315:20)
      at Socket.EventEmitter.emit (domain.js:467:12)
      at addChunk (internal/streams/readable.js:309:12)
      at readableAddChunk (internal/streams/readable.js:284:9)
      at Socket.Readable.push (internal/streams/readable.js:223:10)
      at Pipe.onStreamRead (internal/stream_base_commons.js:188:23)
syropian commented 3 years ago

I actually think this is a bug with Vite / @vitejs/plugin-vue itself — I ran into this in a normal Vite + Vue 3 + TS project!

privatenumber commented 3 years ago

This error is coming from vite-plugin-vue2 (as reported by Vite), but if you're experiencing it in @vitejs/plugin-vue you should report it there.

IIRC, when I did some quick debugging, it was because this plugin was using Babel to parse. I don't recall which one but here are a few:

Curious if these are necessary, since vue-loader doesn't use Babel and if so, if they can be replaced with esbuild for speed.

underfin commented 3 years ago

You should use <script><\/script>. Please see https://github.com/vuejs/vue-loader/issues/506