unplugin-vue-components icon indicating copy to clipboard operation
unplugin-vue-components copied to clipboard

使用pnpm命令创建的vite项目无法在vscode中获得组件类型提示

Open dream2333 opened this issue 2 years ago • 3 comments

如图,yarn和npm创建的工程都能获得类型提示,具有代码高亮 image 而使用pnpm命令创建的工程则没有代码高亮和类型提示,但是运行是正常的,令我感到困惑 image

dream2333 avatar May 29 '22 14:05 dream2333

https://github.com/antfu/unplugin-vue-components/issues/389

damowangzhu avatar May 31 '22 01:05 damowangzhu

问题出现在自动生成的 components.d.ts 文件中的 declare module '@vue/runtime-core' 声明,在 pnpm 中只能访问项目的顶级依赖,而 @vue/runtime-core 是 vue 模块下的依赖,不是顶级依赖,导致声明语句失效。(yarn 和 npm 的 node_modules 平铺目录结构允许访问所有依赖)

解决方案如下:

  1. Volar 同时也读取了 vue 模块中的 GlobalComponents 类型,如果你愿意手动维护 components.d.ts 文件,直接将声明改成 declare module 'vue' 即可。
  2. 也可以直接引入 pnpm add @vue/runtime-core -D 依赖,让声明语句生效即可,但是要注意引入的依赖版本应该与 vue 的版本相同,声明语句才会生效在正确的模块。
  3. 推荐直接修改 .npmrc 配置文件 public-hoist-pattern[]=@vue/runtime-core 将依赖提升至根目录,也可以设置 shamefully-hoist=true 将所有依赖都提升至根目录(不推荐)。

wangyu-personal avatar Jun 09 '22 08:06 wangyu-personal

shamefully-hoist=true已经设置了,但是antv的Col和Row还是没有提示(其他组件有)

rainmanhhh avatar Jun 17 '22 01:06 rainmanhhh

thanks

AxyLm avatar Jan 29 '23 15:01 AxyLm

添加 .npmrc

# .npmrc
# 提升含有 eslint(模糊匹配)、prettier(模糊匹配)、viewerjs(精确匹配) 的依赖包到根 node_modules 目录下
public-hoist-pattern[]=@vue/runtime-core

dmyz avatar Jan 31 '23 01:01 dmyz