You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vue3 TypeScript报错:Module vue has no exported... 类型查找失败求助

修复TypeScript无法找到Vue类型的报错
  • 梳理依赖配置
    Vue 3自带类型定义,无需额外安装@types/vue,如果之前装过Vue2版本的@types/vue,先卸载:

    npm uninstall @types/vue
    

    再确保核心依赖为最新版本:

    npm install vue@latest
    npm install -D typescript @vitejs/plugin-vue
    
  • 修正tsconfig配置
    打开项目的tsconfig.json,确保关键配置项正确:

    {
      "compilerOptions": {
        "target": "ESNext",
        "module": "ESNext",
        "moduleResolution": "Node",
        "strict": true,
        "jsx": "preserve",
        "sourceMap": true,
        "resolveJsonModule": true,
        "isolatedModules": true,
        "esModuleInterop": true,
        "lib": ["ESNext", "DOM"],
        "types": ["vite/client"]
      },
      "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
      "references": [{ "path": "./tsconfig.node.json" }]
    }
    

    重点检查:

    • types数组需包含对应构建工具的环境类型(如Vite项目需vite/client)
    • include需覆盖所有.vue和TypeScript文件
    • 若存在tsconfig.node.json,确保其仅针对Node环境配置,不干扰主TS配置
  • 添加Vue文件类型声明
    在src目录下创建shims-vue.d.ts文件,内容如下:

    declare module '*.vue' {
      import type { DefineComponent } from 'vue'
      const component: DefineComponent<{}, {}, any>
      export default component
    }
    

    该文件用于告知TypeScript如何识别.vue组件类型

  • 重启TypeScript服务
    在VS Code中按下Ctrl+Shift+P(Windows)/Cmd+Shift+P(Mac),选择TypeScript: Restart TS Server,让配置修改生效

内容的提问来源于stack exchange,提问作者passionateLearner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 16:47:08