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

Vue 3.4 + TypeScript使用defineModel时出现mergeModels导出错误

Vue3 + TypeScript 使用defineModel 出现 mergeModels 导出错误的解决方法

我在Vue3项目中结合TypeScript使用defineModel()时,出现了编译错误:

TS2305: Module '"vue"' has no exported member 'mergeModels'.

项目依赖如下:

"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"@vue/compiler-sfc": "^3.4.0",
"ts-loader": "^9.5.1",
"typescript": "^4",
"vue": "^3.4.0",
"vue-loader": "^17.4.0",
"vue-template-compiler": "^2.7.16"

tsconfig配置:

{
    "compilerOptions": {
        "target": "es2022",
        "module": "es2022",
        "strict": true,
        "moduleResolution": "node16",
        "experimentalDecorators": true,
        "noUnusedLocals": false,
        "noUnusedParameters": false,
        "allowSyntheticDefaultImports": true,
        "baseUrl": "./",
        "paths": {
            "@classes*": ["resources/assets/js/classes*"],
            "@assets*": ["resources/assets*"],
            "@ziggy*": ["vendor/tightenco/ziggy*"],
            "@components*": ["resources/assets/js/components*"]
        },
        "jsx": "preserve",
        "noImplicitAny": false
    },
    "include": [
        "resources/assets/js/**/*"
    ]
}

已尝试删除node_modules并重新安装,问题未解决。


解决方法

  • 移除Vue2兼容的依赖:依赖中同时存在Vue3的@vue/compiler-sfc和Vue2的vue-template-compiler,二者版本冲突导致类型定义混乱,卸载vue-template-compiler:

    npm uninstall vue-template-compiler
    # 或 yarn remove vue-template-compiler
    
  • 升级TypeScript版本:Vue3.4要求TypeScript最低版本为4.7,当前typescript: "^4"可能安装的是低于4.7的版本,升级到4.7及以上:

    npm install typescript@^4.7 --save-dev
    # 或 yarn add typescript@^4.7 --dev
    
  • 清理依赖缓存并重新安装:删除锁定文件和依赖后重新安装,确保依赖版本一致:

    rm -rf node_modules package-lock.json
    npm install
    
  • 确认defineModel的使用规范:Vue3.4中defineModel支持自动导入,无需手动导入;若手动导入,确保从vue正确引入:

    import { defineModel } from 'vue'
    const model = defineModel()
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 11:17:42