unplugin-element-plus: Cannot find module 'unplugin-element-plus/vite' or its corresponding type declarations.
VsCode Version: 1.77.1 Node.js: 16.14.2 OS: Windows10 x64 10.0.19045
“vite”: “^4.2.1” “unplugin-element-plus”: “^0.7.0” “typescript”: “^4.9.5”
在vite中使用:
import ElementPlus from "unplugin-element-plus/vite";
报了一个 typescript 错误:
Cannot find module 'unplugin-element-plus/vite' or its corresponding type declarations.
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 8
- Comments: 15
@sjqw @heyongsheng @L-T-G @skyclouds2001 已找到解决这个问题的方法,在你使用的 tsconfig*.json 下的 compilerOptions 中添加如下属性/值:
"moduleResolution": "bundler"错误解决后,引入插件使用的话,插件必须传参数,这个是插件的问题,目前我传的是
useSource: truehttps://github.com/element-plus/unplugin-element-plus#usesource造成这个错误的原因是因为 typescript 的模块解析策略问题,有兴趣可以了解一下,推荐几篇文章:
https://www.typescriptlang.org/docs/handbook/module-resolution.html https://juejin.cn/post/7221551421833314360
“moduleResolution”: “bundler” 使用这个配置后,从element-plus导出的组件类型找不到了。 import type { FormInstance } from ‘element-plus’ // 模块"element-plus"没有导出的成员"FormInstance"