FranckFreiburger / vue3-sfc-loader

Single File Component loader for Vue2 and Vue3. Load .vue files directly from your HTML. No node.js environment, no build step.
MIT License
1.03k stars 116 forks source link

TypeError: t is not a function #95

Closed marxangels closed 2 years ago

marxangels commented 2 years ago

version 0.8.4

image

FranckFreiburger commented 2 years ago

please provide a minimalist testcase

marxangels commented 2 years ago

foo.vue

<template>
  <div></div>
</template>

<script>
import foo from '/lib/bar.js'
export default { }
</script>
marxangels commented 2 years ago

@FranckFreiburger it seems the error is caused by the import statement, whatever the script content is.

FranckFreiburger commented 2 years ago

please give your entry point file (the file where you call loadModule()

marxangels commented 2 years ago

load-vue.js

import '/vue/vue3-sfc-loader.js'

const {loadModule} = window['vue3-sfc-loader']

const options = {
    moduleCache: {vue: Vue},
    async getFile(url) {
        let res = await fetch(url)
        if (!res.ok) throw new Error(res.statusText + ' ' + url)
        let content = await res.text()
        return url.endsWith(".js") ? {content, extname: ".mjs"} : content
    },
    addStyle(textContent) {
        const style = Object.assign(document.createElement('style'), {textContent})
        const ref = document.head.getElementsByTagName('style')[0] || null
        document.head.insertBefore(style, ref)
    },
}

export default function (url) {
    return Vue.defineAsyncComponent(() => loadModule(url, options))
}

@FranckFreiburger is there something wrong?

FranckFreiburger commented 2 years ago

yes, your getFile() is not up to date.

see https://github.com/FranckFreiburger/vue3-sfc-loader/blob/main/CHANGELOG.md#-breaking-changes and https://github.com/FranckFreiburger/vue3-sfc-loader#example

marxangels commented 2 years ago

Great! It works fine. Thank you, Franck.