What is the correct way to register an imported component in a Vue single file component to comply with the eslint-plugin-vue vue/no-unregistered-components guideline?

Recently entering the realm of Vue, I'm in the process of achieving pristine eslint-plugin-vue outcomes on a trial project. However, when inspecting the test file named Home.vue displayed below, an alert is triggered:

The "HelloWorld" component has been used but not registered (vue/no-unregistered-components)
. How can this issue be rectified using correct syntax?

Could this be simply a drawback of the vue/no-unregistered-components ESLint rule itself? Is it possible that the rule does not acknowledge the

export default class Home extends Vue {}
and @Component(...) structure?

<template>
  <v-container fluid>
    <v-layout column align-center>
      <!-- Warning from ESLint: The "HelloWorld" component has been used but not registered. (eslint vue/no-unregistered-components)" is being notified on the HelloWorld tag below -->
      <HelloWorld
        quote="Hello world!"
        author="Jiminy Cricket"
      />
    </v-layout>
  </v-container>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import HelloWorld from '@/components/HelloWorld.vue'

@Component({
  components: {
    HelloWorld
  }
})
export default class Home extends Vue {}
</script>

Update: Below is my .eslintrc.js configuration along with version details of additional tools.

module.exports = {
  env: {
    node: true
  },
  /* ESLint + Prettier config */
  extends: [
    'plugin:vue/base',
    'plugin:vue/essential',
    'plugin:vue/strongly-recommended',
    'eslint:recommended',
    '@vue/typescript/recommended',
    '@vue/prettier',
    '@vue/prettier/@typescript-eslint'
  ],
  parserOptions: {
    ecmaVersion: 2020
  },
  rules: {
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    'vue/no-unregistered-components': [
      'warn',
      { ignorePatterns: ['v(-\\w+)+', 'router-link', 'router-view'] }
    ],
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'space-before-function-paren': [
      'error',
      {
        anonymous: 'always',
        named: 'never',
        asyncArrow: 'always'
      }
    ]
  },
  overrides: [
    {
      // deactivating typescript guidelines for *.config.js files
      files: ['*.config.js'],
      plugins: ['@typescript-eslint'],
      rules: {
        // Unfortunately, there's no direct way to disable all @typescript-eslint/* rules for a *.js file.
        '@typescript-eslint/no-var-requires': 0
      }
    },
    {
      // enforcing the guideline specifically for TypeScript files
      files: ['*.ts', '*.tsx'],
      rules: {
        '@typescript-eslint/explicit-module-boundary-types': ['error']
      }
    },
    {
      // how to enforce the rule solely on Typescript *.vue files???
      //files: ['*.vue?lang=ts'],
      files: ['*.vue'],
      rules: {
        '@typescript-eslint/explicit-module-boundary-types': ['warn']
      }
    }
  ]
}

When running the command

npx vue-cli-service lint --no-fix src\views\Home.vue
(for fixing a single file), the following warning is generated:

warning: The "HelloWorld" component has been used but not registered (vue/no-unregistered-components) at src\views\Home-min.vue:4:7:
  2 |   <v-container fluid>
  3 |     <v-layout column align-center>
> 4 |       <HelloWorld
    |       ^
  5 |         quote="Hello world!"
  6 |         author="Jiminy Cricket"
  7 |       />

1 warning found.

The same red flag pops up within VSCode when utilizing the dbaeumer.vscode-eslint extension. My environment consists of eslint 6.8.0, @vue/cli-service 4.5.9, and eslint-plugin-vue 7.11.1.

Answer №1

Have you properly registered the component in your components section? It's important to register the component after importing it, like so:


<template>
  <v-container fluid>
    <v-layout column align-center>
      <HelloWorld  
        quote="Hello world!"
        author="Jiminy Cricket"
       >
    </v-layout>
  </v-container>
</template>

<script>
import HelloWorld from '@/components'

export default {

...

components: {
  HelloWorld
},

...

</script>

...

Additionally, it seems like you may want to use v-bind for the author and quote props in order to utilize them in the child component.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you provide guidance on how to upload a q-img using a relative path from an object?

I am facing an issue with my Vue 3 / TypeScript app that is using Quasar. I have an object containing the relative path to my images, and I'm attempting to use that path to load the image for a Quasar component q-img. Below is an example of the code: ...

View the docx document within Vue framework

Can someone show me how to preview a docx file in vue.js? I uploaded the docx file using an input tag with type="file". I attempted to use the npm package called vue-doc-preview, but it requires an online URL instead of a local one. ...

Is there a way to convert datetime format to date in a Vue component?

With my Vue component set up like this: <template> ... <td>{{getDate(item.created_at)}}</td> ... </template> <script> export default { ... methods: { getDate(datetime) { ...

Discovering the Vue app container div attribute

I am currently working on a Java app that generates pages server-side based on certain data, such as a publisher for a specific entity. I want to develop a reusable Vue component that can call an API method to request data about the entity that is being vi ...

Having trouble with the Vuejs validation code not functioning correctly?

I need help with a JavaScript function that posts objects to the backend only if all items are numbers. Here is the code snippet I'm working with: var MyApp = new Vue({ el: '#my_element', data: { errors: [], ...

The absence of text is not displayed in an empty slot of a Buefy table

Currently, I am working on a Nuxt project with Buefy implementation. I attempted to create a table with an #empty slot that displays a message when no data is available. However, my code does not seem to be working as expected. If you refer to the Buefy do ...

Troubleshoot: Unable to utilize mapActions with Vuex modules

Having trouble using mapActions to reference actions in my modules. The Vuex docs say that module actions are not namespaced by default, so they should be accessible like main store actions. Here's how I have things set up: Store import * as ModuleA ...

Chorme is throwing a CSRF token mismatch error when working with Laravel API Sanctum

Having an issue with my Vue app and backend Laravel setup. I am using SPA Authentication for authentication. Everything works fine in localhost, but when I deployed it to the server, there are some issues. After sending a login request to sanctum/csrf-co ...

Tips on utilizing these styles as properties for the Vue component

Is there a way I can incorporate these styles as properties for this component? <template> <div> <transition-group name='fade' tag='div'> ... </div> </te ...

Error encountered when deploying mixed content

Currently working on a project and looking to deploy my dev server to firebase hosting. Encountered some Mixed Content errors in Chrome dev tools after deploying the app, indicating that I needed to switch certain source files from http to https. The erro ...

Utilizing Props in Data and Methods in Vue.js

As a newcomer to Vue.js, I am encountering an issue when passing data from a parent component to a child component using props. While I can access the data in the child component, I'm facing difficulties when trying to use it within the child componen ...

New behavior in Vue 3: defineEmits is causing issues with defineProps data

Currently, I am working with Vue 3 and TS 4.4. In one of my components, I am using defineProps to define prop types. However, when I try to add defineEmits, VS Code starts indicating that my props variable is not recognized in the component template. Below ...

Updating locale in Vue-i18n does not result in complete refresh of all components

Just diving into vue-i18n, it looks promising but facing some difficulties in getting it to function properly. Changing the locale updates all template translations correctly, however when script data() { return { locales: { en: this.$i18n.t ...

Impress.js functions properly within a Vue component, however, the 'visibility:hidden;' style is not consistently overridden in standard HTML

Recently purchased a commercial license and attempting to follow the documentation, but encountering issues with getting the animation to function My setup includes Laravel 5.4 and Vue 2 <head> <link rel="stylesheet" href="/css/animate.min.cs ...

Vue.js 3 with TypeScript is throwing an error: "Module 'xxxxxx' cannot be located, or its corresponding type declarations are missing."

I developed a pagination plugin using Vue JS 2, but encountered an error when trying to integrate it into a project that uses Vue 3 with TypeScript. The error message displayed is 'Cannot find module 'l-pagination' or its corresponding type ...

Issue with Laravel Vue search-dropdown and other components failing to render correctly for certain users

We are currently implementing a searchable dropdown menu for our web application using a vue component. Strangely, the component fails to load on my local version (xampp) as well as on the deployed website. However, it displays properly on another develope ...

"Utilize TipTap with the power of your personalized name

Is it feasible to work around the inability to use the name tag on TipTap for sending data through forms in Laravel? Here's an example of what I have in mind: <tiptap-vuetify v-model="content" :extensions="extensions" ...

There is no such property - Axios and TypeScript

I am attempting to retrieve data from a Google spreadsheet using axios in Vue3 & TypeScript for the first time. This is my initial experience with Vue3, as opposed to Vue2. Upon running the code, I encountered this error: Property 'items' does ...

Limiting the table width in TinyMCE

Currently, I am utilizing TinyMCE within a Vue application. I've set up TinyMCE with the table_grid: false configuration, causing a dialog to appear when a table is created. This dialog allows users to specify rows, columns, width, and more. Within t ...

Exploring the differences between this.$emit and this.$root.$emit in Vue.js: a guide to best practices

My Vue2 components are dynamically added and removed using v-if. Sometimes, I need to communicate between these components by using $emit in the sender and $on in the receiver. I have been utilizing this.$root.$emit to broadcast custom events and this.$ro ...