Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obscure error says my component name begins with a zero

Tags:

vue.js

vuejs2

I am getting an obscure error that my component name is zero. But none of my components have a zero for a name. This error is hard to track down. Anyone know what the problem could be so I can move in the right direction to tackle it.

vendor.js:66537 [Vue warn]: Invalid component name: "0". Component names can only contain alphanumeric characters and the hyphen, and must start with a letter.

Heres more information on the error:

enter image description here

Edit: More information:

I have a unique project structure. I have single file components. And each component is split into 2 files like so:

Home.vue:

<template>
    ...
</template>

<style lang="scss">
    ...
</style>

<script src="./home.js"></script>

home.js:

export default {
    ...
}

Edit: debug capture

enter image description here

Edit: home.js

import RecentPostsWidget from './widgets/RecentPosts'
import PagesWidget from './widgets/Pages'

export default {
    components: {
        RecentPostsWidget,
        PagesWidget
    }
}
like image 374
sazr Avatar asked Apr 12 '18 09:04

sazr


3 Answers

I had the same error and it was caused by use of array instead of object in the components. This is how it should looks like

components: {
  RecentPostsWidget,
  PagesWidget
}

This is how I had it when the error appeared:

components: [
  RecentPostsWidget,
  PagesWidget
]
like image 193
Konrad Linkowski Avatar answered Oct 22 '22 19:10

Konrad Linkowski


Try replacing

components: {
    RecentPostsWidget,
    PagesWidget
}

with

components: {
    recentPostsWidget: RecentPostsWidget,
    pagesWidget: PagesWidget
}
like image 2
WebSpanner Avatar answered Oct 22 '22 19:10

WebSpanner


look somewhere for a component that you are using braces: [] and change them to {} Example:

components: [
     Logo,
     Nav
   ],

Switch to:

components: {
     Logo,
     Nav
   },
like image 2
Francisco Mendoza Avatar answered Oct 22 '22 19:10

Francisco Mendoza