前言
创建 Vue3 + Vuex + Vite + TypeScript 项目时,从 vue 导入 InjectionKey 以实现 store 的类型检查,执行时报错
Uncaught SyntaxError: The requested module '/node_modules/.vite/deps/vue.js?v=xxxx' does not provide an export named 'InjectionKey'
错误情况
按照 TypeScript 支持 | Vuex 文档说明配置 index.ts 文件,运行后报错
import { InjectionKey } from 'vue'; // 执行报错
解决方法
在 GitHub 查找到解决方案,将导入语句替换为以下结构即可
import type { InjectionKey } from 'vue'; // 成功执行