Skip to content
This repository was archived by the owner on Dec 6, 2021. It is now read-only.
This repository was archived by the owner on Dec 6, 2021. It is now read-only.

Typecast in Vue SFC prop results in Babel error? #740

@scbash

Description

@scbash

I'm relatively new to web development, so hopefully is a fairly trivial configuration change rather than a bug, but here goes...

I'm using Typescript in a Vue SFC, and I'm trying to enforce the type of a component property:

... snip ...
<script lang="ts">
import type { PropType } from 'vue'
import type { Emitter as MittEmitter } from 'mitt'
... snip ...
export default {
... snip ...
  props: {
    eventBus: {
      type: Object as PropType<MittEmitter>,
      required: true
    }
  },
... snip ...
}

This produces an error during poi --serve:

./src/components/Library.vue?vue&type=script&lang=ts)
Module build failed (from ./node_modules/poi/lib/webpack/babel-loader.js):
SyntaxError: .../src/components/Library.vue: Unexpected token, expected "," (68:19)

  66 |   props: {
  67 |     eventBus: {
> 68 |       type: Object as PropType<MittEmitter>,
     |                    ^
  69 |       required: true
  70 |     }
  71 |   },

which lead me to this VueJS Developers post implying Babel needs to be using the Typescript parser (search for "babel eslint parser"), but AFAICT the Poi Babel preset does use the Typescript parser?

My package.json is vanilla (just dependencies), and I'm not overriding any Poi defaults. I am working with Vue 3rc5, though AFAIK this code isn't Vue 3 specific. Other possibly relevant versions:

$ npx poi --version
poi/12.9.0 linux-x64 node-v13.13.0
$ node --version
v13.13.0
$ npm --version
6.14.4

It seems like I'm close, but obviously still missing something. I will very much appreciate any tips, thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions