vuejs / language-tools

⚡ High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.55k stars 373 forks source link

Module `@vue/runtime-core` cannot be reconized by language server #4401

Closed RayGuo-ergou closed 1 month ago

RayGuo-ergou commented 1 month ago

I found this issue when working with a project uses element-plus, they use @vue/runtime-core to declare global components. I did some research and seems vue document also uses vue now ( I remembered before prefer @vue/runtime-core?)

e.g. for code

import BaseInput from '@/components/BaseInput.vue'
import BaseButton from '@/components/BaseButton.vue'
declare module 'vue' {
  export interface GlobalComponents {
    BaseInput: typeof BaseInput,
  }
}

declare module '@vue/runtime-core' {
  export interface GlobalComponents {
    BaseButton: typeof BaseButton,
  }
}

image

minimal reproduction: https://github.com/RayGuo-ergou/volar_reproduction_global_component_ts

Language server version: 2.0.19
johnsoncodehk commented 1 month ago

This depends on whether the module is located in the top directory of node_modules.

When using npm, both definitions are valid. But when using pnpm, the top directory of node_modules only contains vue and not @vue/runtime-core, so declare module '@vue/runtime-core' is invalid.

This is a solution to a different but related issue: https://github.com/vuejs/language-tools/issues/4170#issuecomment-2025528945

RayGuo-ergou commented 1 month ago

that makes sense, thank you!