Fix Vue 3 "Failed to resolve component" warnings

aaronblondeau - Feb 14 '22 - - Dev Community

I am experimenting with an interesting UI Tookit that I found for Vue by Microsoft : https://docs.microsoft.com/en-us/fluent-ui/web-components/integrations/vue.

I started a stock Vue3 Project using the Getting started instructions. I then followed the setup instructions for the Fluent UI components. They worked right away.

Unfortunately, there was an annoying set of errors in the JS console like this:

Failed to resolve component: fluent-button

Image description

It took a ton of searching to find the solution. I wound up having to tweak vite.config.ts to be like this :



import { fileURLToPath, URL } from "url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    // Fixes warnings like : Failed to resolve component: fluent-button
    vue({
      template: {
        compilerOptions: {
          // treat all tags with a dash as custom elements
          isCustomElement: (tag) => tag.startsWith("fluent-"),
        },
      },
    }),
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
});


Enter fullscreen mode Exit fullscreen mode

I also had a super annoying problem where every ".vue" import made VSCode angry:

Image description

The level of complexity in Vue has been making me more and more concerned lately. Why can't a brand new project work without errors?

For this one I had to add a file called shims-vue.d.ts:



declare module "*.vue";


Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .