vuejs / language-tools

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

Cannot import Vue 3 types from @vue/runtime-dom. If you are using Vue 2, you may need to install @vue/runtime-dom in additionally. #175

Closed ercmage closed 3 years ago

ercmage commented 3 years ago

I am using latest vue-cli (vue3) with vue add typescript. Volar doesn't work when i installed it, any idea how to fix this?

Screen Shot 2021-05-09 at 17 11 02

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "experimentalDecorators": true,
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "webpack-env"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}
johnsoncodehk commented 3 years ago

Have you install node_modules? If yes please show your package.json.

ercmage commented 3 years ago

@johnsoncodehk yes of course

Any ideas how to fix? Thank you

{
  "name": "myproj",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "i18n:report": "vue-cli-service i18n:report --src \"./src/**/*.?(js|vue)\" --locales \"./src/locales/**/*.json\""
  },
  "dependencies": {
    "@headlessui/vue": "^1.0.0",
    "@lottiefiles/lottie-player": "^1.0.3",
    "@vueuse/core": "^4.9.0",
    "@walletconnect/web3-provider": "^1.4.1",
    "core-js": "^3.6.5",
    "echarts": "^5.1.0",
    "ethers": "^5.1.4",
    "vue": "^3.0.0",
    "vue-class-component": "^8.0.0-0",
    "vue-cleave-component": "^3.0.1",
    "vue-echarts": "^6.0.0-rc.4",
    "vue-ellipse-progress": "2.0.0-beta.1",
    "vue-i18n": "^9.1.0",
    "vue-router": "^4.0.0-0",
    "vue-router-layout": "^0.3.0",
    "vue-tippy": "^6.0.0-alpha.28",
    "vue3-jazzicon": "^0.1.2"
  },
  "devDependencies": {
    "@intlify/vue-i18n-loader": "^2.1.0",
    "@types/async": "^3.2.6",
    "@typescript-eslint/eslint-plugin": "^4.22.0",
    "@typescript-eslint/parser": "^4.18.0",
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-typescript": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/compiler-sfc": "^3.0.0",
    "@vue/eslint-config-typescript": "^7.0.0",
    "@windicss/plugin-scrollbar": "^1.2.3",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^7.9.0",
    "typescript": "^4.2.4",
    "vue-auto-routing": "^1.0.0",
    "vue-cli-plugin-auto-routing": "~1.2.0",
    "vue-cli-plugin-i18n": "~2.1.0",
    "vue-cli-plugin-import-components": "~1.0.1",
    "vue-cli-plugin-windicss": "~0.1.5",
    "vue-eslint-parser": "^7.6.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ]
}

my vscode .settings

{
  "i18n-ally.keystyle": "nested",
  "i18n-ally.localesPaths": [
    "src/locales"
  ],
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true,
  },
  "editor.defaultFormatter": "dbaeumer.vscode-eslint",  
  "editor.gotoLocation.multipleReferences": "goto",
  "editor.gotoLocation.multipleDefinitions": "goto",
  "editor.gotoLocation.multipleDeclarations": "goto",
  "editor.gotoLocation.multipleImplementations": "goto",
  "editor.gotoLocation.multipleTypeDefinitions": "goto",
}
johnsoncodehk commented 3 years ago

I tried your package.json and tsconfig.json with yarn and pnpm but can't reproduce, can you try this template? If works please compare different.

ercmage commented 3 years ago

Hi thanks, yeah it's working. I also try to create fresh vue-cli project, and volar works just fine there, so i moved all my source to the new vue project and it works. Don't know what caused it before, very strange.

TheDutchCoder commented 3 years ago

I still get this every time I start VSCode. It doesn't seem to affect anything though.

I wonder if it's due to me opening a monorepo where Vue is not installed in the root, but in one of the sub packages.

johnsoncodehk commented 3 years ago

@TheDutchCoder some features like html elements type-checking, GlobalComponents interface... may not working in some *.vue file.

If you can't resolve this warning, please provide a minimal reproduce.

TheDutchCoder commented 3 years ago

I have a feeling it has something to do with import { defineComponent, ref, Ref } from 'vue' Auto-import actually resolves to '@vue/runtime-dom', not 'vue', so I'm wondering if there's some sort of module mapping that's off?

To clarify, if I start typing export default defineCom, the auto-import will add import { defineComponent } from '@vue/runtime-dom', instead of import { defineComponent } from 'vue' (which is what I would expect).

tjx666 commented 3 years ago

Reproduce repository: https://github.com/tjx666/electron-vue-vite-boilerplate/tree/9e1f66708f12e76ca8a148737d4af29d65d2c906

I think this is volar bug, because access to @vue/runtime-dom is not a security behavior.

johnsoncodehk commented 3 years ago

@tjx666 this is TS problem, see https://github.com/tjx666/electron-vue-vite-boilerplate/pull/1.