vue3.x 里面使用 vuex4.x 无法找到模块“vuex”的声明文件

报错如下

解决

https://github.com/vuejs/vuex/issues/2223

https://github.com/vuejs/vuex/issues/2213#issuecomment-1592267216

我使用了这个方式处理

在根目录新建一个 vuex.d.ts 文件

ts 复制代码
declare module "vuex" {
    export * from "vuex/types/index.d.ts";
    export * from "vuex/types/helpers.d.ts";
    export * from "vuex/types/logger.d.ts";
    export * from "vuex/types/vue.d.ts";
}


tsconfig.app.json 配置文件里面添加这个文件

json 复制代码
{
  "extends": "@vue/tsconfig/tsconfig.dom.json",
  "compilerOptions": {
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
    "types": ["vite/client"],
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    },

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "erasableSyntaxOnly": true,
    "noFallthroughCasesInSwitch": true,
    "noUncheckedSideEffectImports": true
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "vuex.d.ts"
  ]
}
相关推荐
Sapphire~1 天前
Vue3-012 vue2与vue3中的computed
vue3
Sapphire~4 天前
Vue3-11 toRefs 和 toRef
vue3
华玥作者5 天前
uni-app + Vite 项目中使用 @uni-helper/vite-plugin-uni-pages 实现自动路由配置(超详细)
前端·uni-app·vue·vue3·vite
独立开发者阿乐7 天前
Vue3中Markdown解析与渲染的完整解决方案:从安全到性能优化
web安全·性能优化·vue3·前端开发·语法高亮·markdown解析·markdown-it
Sapphire~8 天前
Vue3-10 ref与reactive创建响应式数据的区别
vue3
Irene19918 天前
Vue3 TypeScript 项目中,Emits 验证的使用场景
typescript·vue3·验证
箫笙默8 天前
Vue3基础笔记
笔记·vue·vue3
Sapphire~8 天前
Vue3-09 创建响应式数据(基本类型ref和对象类型reactive)
vue3
Sapphire~9 天前
Vue3-02 脚手架创建项目及文件解释作用
vue3
Cherry的跨界思维10 天前
28、AI测试环境搭建与全栈工具实战:从本地到云平台的完整指南
java·人工智能·vue3·ai测试·ai全栈·测试全栈·ai测试全栈