Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No property 'component' error after creating new project with vue-cli

This part of the documentation of Vue3 says that it should be possible to call a function component on the object returned by createApp.

I created a project using vue-cli with vue create myApp.
I selected Vue3 and added typescript to the project.

The generated project contains a file named main.ts where createApp is used.
I tried to use the component method as indicated in the doc and got the following error.

ERROR in src/main.ts:6:5
TS2339: Property 'component' does not exist on type 'ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>>'.
// main.ts
import { createApp } from 'vue'
import App from './App.vue'

const app = createApp(App).mount('#app')

app.component("er", {})

Is there more setup to do in order to use all feature of Vue ?

like image 819
lblenner Avatar asked Dec 20 '25 08:12

lblenner


1 Answers

createApp(App) and createApp(App).mount('#app') are different object. The former is Vue instance, the latter is component instance.

It should be:

const app = createApp(App)
app.component("er", {})

const vm = app.mount('#app')
like image 161
Estus Flask Avatar answered Dec 23 '25 00:12

Estus Flask



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!