Adam Starrh
Adam Starrh

Reputation: 6958

Vue 3: Vue.createApp is not a constructor

I am brand new to Vue and am trying to learn how to use it.

I think I am getting tripped up trying to mount a new Vue app.

Here is what I can get to work:

<script src="https://unpkg.com/vue"></script>
<script>
const vm = new Vue({})
</script>

from there I am able to mount it and use everything correctly.

However, this currently loads an older version of Vue (2.6.7)

I'd like to learn on the newest version (Vue 3) so I tried importing the package recommended by Vue docs:

<script src="https://unpkg.com/vue@next"></script>
<script>
const vm = new Vue({})
</script>

and I get the following error in console:

Uncaught TypeError: Vue is not a constructor

I also tried mimicking the syntax from Vue 3's docs.

<script src="https://unpkg.com/vue@next"></script>
<script>
const vm = new Vue.createApp({})
</script>

but it throws the same error:

Uncaught TypeError: Vue.createApp is not a constructor

Using a different CDN or a specific version ([email protected]) also gives me the same result.

What am I doing wrong?

Upvotes: 9

Views: 13285

Answers (1)

Boussadjra Brahim
Boussadjra Brahim

Reputation: 1

createApp is not an object it's a function that returns an instance of vue app, so it should be :

 const vm = Vue.createApp({}) //remove the new

createApp
Returns an application instance which provides an application context. The entire component tree mounted by the application instance share the same context
const app = Vue.createApp({})

Upvotes: 19

Related Questions