Ortemon
Ortemon

Reputation: 19

How do I configure .vue files import from .ts file in vim?

I have encountered a problem trying to configure NeoVim to work with Vue. On a freshly installed LunarVim instance I'm trying to work with .ts files, but there is an error with importing .vue file. My treesitter has configuration for vue and typescript. Also tsserver and volar LSPs work just fine. There is autocompletion and everything. But in imports there are errors: Cannot find module './App.vue' or its corresponding type declarations. And yes, I'm sure that there is App.vue file, the problem is only with .vue files.enter image description here

I've tried reinstalling tsserver and volar, but it didn't help.

Upvotes: 1

Views: 375

Answers (1)

Caleb Bertrand
Caleb Bertrand

Reputation: 414

The issue for me was that I did not have the @vue/typescript-plugin package installed and connected to ts_ls. More info here: https://github.com/vuejs/language-tools

My lua config now looks like this, and I have the correct types on imported vue files:

lspconfig.ts_ls.setup({
    init_options = {
    plugins = {
      {
        name = "@vue/typescript-plugin",
        location = "/home/dev/.nvm/versions/node/v20.18.0/lib/node_modules/@vue/language-server",
        languages = {"javascript", "typescript", "vue"},
      },
    },
  },
  filetypes = {
    "javascript",
    "typescript",
    "vue",
  },
})
lspconfig.volar.setup{}

Upvotes: 0

Related Questions