Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module 'unplugin-element-plus/vite' or its corresponding type declarations. #189

Open
yxb94616 opened this issue Apr 11, 2023 · 15 comments

Comments

@yxb94616
Copy link

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.

@sjqw
Copy link

sjqw commented Apr 12, 2023

我也遇到了同样的错误,求解决方式

@heyongsheng
Copy link

@sjqw @yxb94616 我也遇到了这个问题,暂时没找到很好的解决方案,但我找到了别的办法,因为我之前的项目这么写是没问题的,所以我查看了版本号,之前的安装的是0.4.1的,所以如果你也不知道怎么解决,安装0.4.1版本可能是一个不错的办法,或者直接使用// @ts-ignore忽略这一行的报错

npm i unplugin-element-plus@0.4.1 -D
// or

// @ts-ignore
import ElementPlus from 'unplugin-element-plus/vite'

@L-T-G
Copy link

L-T-G commented Apr 16, 2023

同上,也遇到了这个问题

@skyclouds2001
Copy link

同上,我也遇到了这个问题

OS: Windows10 x64
IDE:WebStorm 2023.1
Node:18.13.0

vite:4.2.1
typescript:5.0.2
unplugin-element-plus:0.7.0

@yxb94616
Copy link
Author

yxb94616 commented Apr 17, 2023

@sjqw @heyongsheng @L-T-G @skyclouds2001
已找到解决这个问题的方法,在你使用的 tsconfig*.json 下的 compilerOptions 中添加如下属性/值:

"moduleResolution": "bundler"

错误解决后,引入插件使用的话,插件必须传参数,这个是插件的问题,目前我传的是

useSource: true
https://github.com/element-plus/unplugin-element-plus#usesource

造成这个错误的原因是因为 typescript 的模块解析策略问题,有兴趣可以了解一下,推荐几篇文章:

https://www.typescriptlang.org/docs/handbook/module-resolution.html
https://juejin.cn/post/7221551421833314360

@tripflex
Copy link

+1

@Allihol
Copy link

Allihol commented May 5, 2023

"moduleResolution": "bundler"
使用这个配置后,从element-plus导出的组件类型找不到了。
import type { FormInstance } from 'element-plus'
// 模块"element-plus"没有导出的成员"FormInstance"

@yxb94616
Copy link
Author

yxb94616 commented May 5, 2023

"moduleResolution": "bundler" 使用这个配置后,从element-plus导出的组件类型找不到了。 import type { FormInstance } from 'element-plus' // 模块"element-plus"没有导出的成员"FormInstance"

我这里没有这个问题呐
image

@Allihol
Copy link

Allihol commented May 5, 2023

"moduleResolution": "bundler" 使用这个配置后,从element-plus导出的组件类型找不到了。 import type { FormInstance } from 'element-plus' // 模块"element-plus"没有导出的成员"FormInstance"

我这里没有这个问题呐 image

你的package.json中有type:"module"吗

@yxb94616
Copy link
Author

yxb94616 commented May 5, 2023

"moduleResolution": "bundler" 使用这个配置后,从element-plus导出的组件类型找不到了。 import type { FormInstance } from 'element-plus' // 模块"element-plus"没有导出的成员"FormInstance"

我这里没有这个问题呐 image

你的package.json中有type:"module"吗

没有呢

@Allihol
Copy link

Allihol commented May 5, 2023

"moduleResolution": "bundler" 使用这个配置后,从element-plus导出的组件类型找不到了。 import type { FormInstance } from 'element-plus' // 模块"element-plus"没有导出的成员"FormInstance"

我这里没有这个问题呐 image

你的package.json中有type:"module"吗

没有呢

难搞,我已经通过回退至0.4.1解决了

@Lixuhuilll
Copy link

同样的问题,我是通过将项目ts版本降级解决的,当我把TypeScript升级到5.0.4后就出现了这个问题,此时,Webstorm下方提示当前项目为TypeScript 5.0.4,没有识别到这是Vue项目,不仅是这个插件报错,连导入.vue文件都报错。
image
我将TypeScript版本回退到4.8.4后,一切都恢复了正常,WebStorm正确认识到,这是一个使用TypeScript的Vue项目,而不是一个纯粹的TypeScript项目
image

@kisekiremi
Copy link

just add // @ts-ignore

@skyclouds2001
Copy link

just add // @ts-ignore

if using @ts-ignore to disable this ts error, @ts-expect-error is much better

@sathish099
Copy link

just add // @ts-ignore

if using @ts-ignore to disable this ts error, @ts-expect-error is much better

Yeah!👍 we expected for more better! @element-bot #unplugin-element-plus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants