运行环境vue3 + Vite + TypeScript
在导入vuex的时候
import {createStore} from 'vuex'
出现如下错误提示
无法找到模块“vuex”的声明文件。“E:/workspace/TuWenBaoDian/tuwenbaodian/tuwenbaodian.admin/node_modules/.pnpm/vuex@4.0.2_vue@3.3.9/node_modules/vuex/dist/vuex.mjs”隐式拥有 "any" 类型。
There are types at 'e:/workspace/TuWenBaoDian/tuwenbaodian/tuwenbaodian.admin/node_modules/vuex/types/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'vuex' library may need to update its package.json or typings.ts(7016)
解决方法
在vite-env.s.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";
}