近期使用vue3+ts+vite项目打包的时候,遇到一个问题,截图如下:
错误翻译
Cannot find module '@/store/index' or its corresponding type declarations.
找不到xxx模块或者声明文件
An import declaration can only be used at the top level of a namespace or module.
导入声明的文件只能在顶部使用
解决办法:
把import xxx from 'xxx'全部放在顶部(script后)
报错前:
<script setup lang="ts">
import { ref, reactive, onMounted, nextTick } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import type { FormInstance, FormRules } from 'element-plus'
const router = useRouter()
import useStore from '@/store/index'
const storeUser = useStore()
</script>
处理后: 文章来源:https://www.toymoban.com/news/detail-423089.html
<script setup lang="ts">
import { ref, reactive, onMounted, nextTick } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import useStore from '@/store/index'
import type { FormInstance, FormRules } from 'element-plus'
const router = useRouter()
const storeUser = useStore()
</script>
再次运行yarn build,成功打包!!!!文章来源地址https://www.toymoban.com/news/detail-423089.html
到了这里,关于Cannot find module ‘@/store/index‘ or its corresponding type declarations.的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!