Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i use vue2-sfc-loader ,vsersion 0.8.3 ,hava one erro #92

Closed
fushengruomengzhang opened this issue Jul 6, 2021 · 6 comments
Closed

i use vue2-sfc-loader ,vsersion 0.8.3 ,hava one erro #92

fushengruomengzhang opened this issue Jul 6, 2021 · 6 comments

Comments

@fushengruomengzhang
Copy link

vue version : v2.6.14
vue2-sfc-loader version : 0.8.3
error:

Uncaught (in promise) TypeError: t is not a function
    at vue2-sfc-loader.js:65
    at vue2-sfc-loader.js:65
    at async P (vue2-sfc-loader.js:65)
    at async Module.N (vue2-sfc-loader.js:65)
@fushengruomengzhang fushengruomengzhang added bug Something isn't working unconfirmed Unconfirmed issue labels Jul 6, 2021
@FranckFreiburger
Copy link
Owner

please give more details (browser version, minimal test case, ...)

@leecbryant
Copy link

leecbryant commented Jul 6, 2021

I am getting the same error from Vue3-sfc-loader. This is going directly from 0.7.3 to 0.8.3. (Only difference in my code being the import of 0.8.3) Any recommendations?

Error:

Uncaught (in promise) TypeError: t is not a function
    at vue3-sfc-loader-083.js:69

@fushengruomengzhang
Copy link
Author

fushengruomengzhang commented Jul 7, 2021

please give more details (browser version, minimal test case, ...)

Demo:
Index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo</title>
</head>
<body>
<div id="app"></div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script src="./vue2-sfc-loader.js"></script> <!--①-->
<script>
    const options = {
        moduleCache: {vue: Vue},
        getFile(url) {
            if (!/.*?\.js|.mjs|.css|.less|.vue$/.test(url)) {
                url = url + '.vue'
            }
            return fetch(url).then(res => {
                return !res.ok ? Promise.reject(res) : res.text().then(content => {
                    if (/.*?\.js|.mjs$/.test(url)) {
                        return {content: content, type: ".mjs"}
                    } else if (/.*?\.vue$/.test(url)) {
                        return {content: content, type: ".vue"};
                    }
                    return content;
                });
            })
        },
        addStyle(textContent, url) {
            if (url) {
                let linkElement = document.createElement('link');
                linkElement.setAttribute('rel', 'stylesheet')
                linkElement.setAttribute('type', 'text/css')
                linkElement.setAttribute('href', url)
                document.head.insertBefore(linkElement,
                    document.head.getElementsByTagName('style')[0] || null)
            } else if (textContent) {
                let styleElement = document.createElement('style');
                document.head.insertBefore(Object.assign(styleElement, {textContent}),
                    document.head.getElementsByTagName('style')[0] || null);
            }
            return null;
        },
        handleModule(type, textContent, path, options) {
            switch (type) {
                case '.css':
                    return options.addStyle(textContent, path);
                case '.less':
                    console.error('.......')
            }
        },
        log(type, ...args) {
            console.log(type, ...args);
        }
    };
    const {loadModule} = window['vue2-sfc-loader'];
    const loadVue = (vuePath) => loadModule(vuePath, options)
    new Vue({
        name: 'project',
        el: '#app',
        render: async h => h(await loadVue('./app.vue')),
    })
</script>
</html>

app.vue

<template>
  <div name="app">
    is demo
  </div>
</template>

<script>
export default {
  name: "app",
  components: {},
  data() {
    return {}
  },
  created() {
  },
  methods: {}
}
</script>

:: ①:Download from 'https://cdn.jsdelivr.net/npm/vue3-sfc-loader/dist/vue2-sfc-loader.js'
image

::①:Amend to read <script src="https://cdn.jsdelivr.net/npm/vue3-sfc-loader/dist/vue2-sfc-loader.js"></script>
error:
image

@fushengruomengzhang
Copy link
Author

I am getting the same error from Vue3-sfc-loader. This is going directly from 0.7.3 to 0.8.3. (Only difference in my code being the import of 0.8.3) Any recommendations?

Error:

Uncaught (in promise) TypeError: t is not a function
    at vue3-sfc-loader-083.js:69

Sorry, I have an error using 0.8.3, so I am currently using 0.7.3

@FranckFreiburger
Copy link
Owner

Before vue3-sfc-loader v1.0.0, API may change quickly.
At each release, try to take a look at https://github.com/FranckFreiburger/vue3-sfc-loader/blob/main/CHANGELOG.md

In your case, you are using the old API :

getFile() : see https://github.com/FranckFreiburger/vue3-sfc-loader/blob/main/CHANGELOG.md#080-2021-05-31
handleModule is now a function, see https://github.com/FranckFreiburger/vue3-sfc-loader/blob/main/CHANGELOG.md#060-2021-03-20

@FranckFreiburger FranckFreiburger removed bug Something isn't working unconfirmed Unconfirmed issue labels Jul 7, 2021
@fushengruomengzhang
Copy link
Author

I am getting the same error from Vue3-sfc-loader. This is going directly from 0.7.3 to 0.8.3. (Only difference in my code being the import of 0.8.3) Any recommendations?
Error:

Uncaught (in promise) TypeError: t is not a function
    at vue3-sfc-loader-083.js:69

Sorry, I have an error using 0.8.3, so I am currently using 0.7.3

I have modified the option. Please refer to it.

const options = {
    moduleCache: {vue: Vue},
    getFile(url) {
        url = /.*?\.js|.mjs|.css|.less|.vue$/.test(url) ? url : `${url}.vue`
        const type = /.*?\.js|.mjs$/.test(url) ? ".mjs" : /.*?\.vue$/.test(url) ? '.vue' : /.*?\.css$/.test(url) ? '.css' : '.vue';
        const getContentData = asBinary => fetch(url).then(res => !res.ok ? Promise.reject(res) : asBinary ? res.arrayBuffer() : res.text())
        return {getContentData: getContentData, type: type}
    },
    addStyle(textContent, url) {
        if (url) {
            let linkElement = document.createElement('link');
            linkElement.setAttribute('rel', 'stylesheet')
            linkElement.setAttribute('type', 'text/css')
            linkElement.setAttribute('href', url)
            document.head.insertBefore(linkElement,
                document.head.getElementsByTagName('style')[0] || null)
        } else if (textContent) {
            let styleElement = document.createElement('style');
            document.head.insertBefore(Object.assign(styleElement, {textContent}),
                document.head.getElementsByTagName('style')[0] || null);
        }
        return null;
    },
    handleModule(type, getContentData, path, options) {
        switch (type) {
            case '.css':
                return options.addStyle(getContentData(false), path);
            case '.less':
                console.error('.......')
        }
    },
    log(type, ...args) {
        console.log(type, ...args);
    }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants