Closed fushengruomengzhang closed 3 years ago
vue file content:
<template> <div> hello user detail </div> </template> <script type="module"> import {user} from "./test.js" export default { name: "userDetail", data() { return {} }, created() { console.log(user) }, methods: {} } </script>
test.js file content
export const user = { userName: "root", password: "zfs1111" }
error message
SyntaxError: 'import' and 'export' may appear only with 'sourceType: "module"' (1:0) at De._raise (vue3-sfc-loader.js:19) at De.raiseWithData (vue3-sfc-loader.js:19) at De.assertModuleNodeAllowed (vue3-sfc-loader.js:19) at De.parseStatementContent (vue3-sfc-loader.js:19) at De.parseStatement (vue3-sfc-loader.js:19) at De.parseBlockOrModuleBlockBody (vue3-sfc-loader.js:19) at De.parseBlockBody (vue3-sfc-loader.js:19) at De.parseProgram (vue3-sfc-loader.js:19) at De.parseTopLevel (vue3-sfc-loader.js:19) at De.parse (vue3-sfc-loader.js:19) Promise.catch (async) extractComponentsGuards @ vue-router.js:1991 (anonymous) @ vue-router.js:3070 Promise.then (async) navigate @ vue-router.js:3065 pushWithRedirect @ vue-router.js:2961 push @ vue-router.js:2901 loadMenuRouter @ VM1757:103 eval @ VM1757:57 Promise.then (async) nextTick @ vue.global.js:1457 created @ VM1757:55 callWithErrorHandling @ vue.global.js:1370 callWithAsyncErrorHandling @ vue.global.js:1379 callSyncHook @ vue.global.js:7107 applyOptions @ vue.global.js:7038 finishComponentSetup @ vue.global.js:7718 setupStatefulComponent @ vue.global.js:7649 setupComponent @ vue.global.js:7589 mountComponent @ vue.global.js:5311 processComponent @ vue.global.js:5287 patch @ vue.global.js:4915 componentEffect @ vue.global.js:5403 reactiveEffect @ vue.global.js:410 effect @ vue.global.js:385 setupRenderEffect @ vue.global.js:5368 mountComponent @ vue.global.js:5327 processComponent @ vue.global.js:5287 patch @ vue.global.js:4915 render @ vue.global.js:5988 mount @ vue.global.js:4253 app.mount @ vue.global.js:9375 (anonymous) @ global.config.js:339 mount @ global.config.js:338 (anonymous) @ index.js:14 Promise.then (async) (anonymous) @ index.js:14 Promise.then (async) (anonymous) @ index.js:13 Promise.then (async) (anonymous) @ index.js:13 Promise.then (async) (anonymous) @ index.js:13 Promise.then (async) (anonymous) @ index.js:12 Promise.then (async) (anonymous) @ index.js:12 async function (async) (anonymous) @ index.js:10 (anonymous) @ index.js:15 vue-router.js:1995 Uncaught (in promise) Error: Couldn't resolve component "default" at "/userDetail" at vue-router.js:1995
Solution: https://github.com/FranckFreiburger/vue3-sfc-loader/issues/14#issuecomment-758794153
vue file content:
test.js file content
error message