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

非Vite(Webpack)Vue3+TypeScript项目createApp类型报错求助

解决Vue3中TypeScript报错“module 'vue' has no exported member 'createApp'”

问题背景

项目使用Webpack构建(未采用Vite),Webpack构建流程正常,但TypeScript检查出现异常:编辑器内、执行tsc或vue-tsc编译时均提示“module 'vue' has no exported member 'createApp'”。

项目包含根目录与vue-app目录两个tsconfig.json文件,根目录配置已排除vue-app目录。尝试过重启TS Server、安装@vue/runtime-dom等操作,问题未得到解决。

项目结构

root
|__tsconfig.json
|__ vue-app 
     |__ tsconfig.json

vue-app目录的tsconfig.json

{
  "compilerOptions": {
    "types": ["vue"],
    "strict": true,
    "module": "esnext",
    "target": "esnext",
    "lib": ["esnext", "dom"],
    "sourceMap": true,
    "outDir": ".out",
    "rootDir": ".",
    "noUnusedLocals": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true
  }
}

根目录的tsconfig.json

{
  "compilerOptions": {
    "module": "Node16",
    "target": "ES2022",
    "lib": ["ES2022"],
    "sourceMap": true,
    "rootDir": ".",
    "outDir": ".out",
    "strict": true /* enable all strict type-checking options */,
    // aliases declarations:
    "paths": {
      "@core/*": ["./core/*"],
      "@root/*": ["./extension-src/*"]
    },
    // inversify config:
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
  "exclude": [
    "node_modules",
    ".vscode-test",
    "**/vue-app/**",
  ]
}

依赖版本

  • @types/vue": "^1.0.31"
  • vue": "^3.5.6"

更新说明

安装@vue/runtime-dom后,vue-app目录无法访问该模块;移除根配置中vue-app的排除项后可访问,但原报错问题依旧存在。

解决方案

核心原因

你安装的@types/vue是Vue 1.x版本的类型定义包,但项目实际使用的是Vue 3.x,二者类型定义完全不兼容,导致TypeScript无法识别Vue3的createApp方法。Vue 3.x从3.0版本开始已内置完整类型定义,无需额外安装@types/vue。

解决步骤

  1. 卸载冲突的类型包
    执行命令卸载@types/vue:
npm uninstall @types/vue
# 若使用yarn则执行:
yarn remove @types/vue
  1. 验证配置(可选)
    vue-app目录的tsconfig.json中"types": ["vue"]配置可保留,Vue3的内置类型会被自动识别,无需修改。

  2. 重启TS Server并重新编译

  • 在编辑器(如VSCode)中按Ctrl+Shift+P,输入TypeScript: Restart TS Server重启服务
  • 重新执行tsc或vue-tsc编译,验证问题是否解决

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 05:21:15