5

While working with Vue CLI 4.5.x, I tried the following code:

import Vue from "vue"
import App from './App.vue'

new Vue({
    el: "#app",
    render: h=> h(App)
})

But unfortunately, it gave the following warnings:

"export 'default' (imported as 'Vue') was not found in 'vue'

What I can conclude from this, is that Vue CLI 4.5.x has stopped this way of creating an application where you first create a Vue instance.

To initialize the main application, the official way is as follows:

import { createApp } from 'vue'
import App from './App.vue'

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

I'm not sure if my conclusion is correct or not. It would be a great help if somebody would concrete my conclusion, as so far I have not found any proof of that in official documentation of vue.

Moreover, the later code comes baked with Vue CLI 4.5.* application instance, while former code is true when using the CDN.

Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164
Gursewak Singh
  • 642
  • 1
  • 7
  • 20

1 Answers1

4

You've installed vue 3 using vue-cli 4 and this version has this new global api for creating new app :

import { createApp } from 'vue'

const app = createApp({})

You're still able to create apps using vue 2 based on vue cli 4 but you should indicate the version when you launch new project.

tony19
  • 125,647
  • 18
  • 229
  • 307
Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164
  • Yeah I saw the option of Vue2 but I thought I should better start with vue 3, you know like sort of ready for the future. But thanks Boussadjra.. you are a great help. – Gursewak Singh Sep 24 '20 at 14:34
  • @GursewakSingh it's not the time to start with vue 3 if you're new in vue, you should focus on vue 2 because there's a lot of resources on internet that could help you learning vue 2, vue 3 is released officially since the last Friday – Boussadjra Brahim Sep 24 '20 at 16:25
  • Thanks, but I am not new to Vue its just like coming to vue after 4 or 5 months. – Gursewak Singh Sep 25 '20 at 05:57
  • Since we cannot create a Vue instance in vue 3 therefore we cannot create a event bus.. if am not wrong....? – Gursewak Singh Sep 25 '20 at 07:10
  • You're right but there's a solution please check my answer [here] for more details, don't forget to give a point if it is helpful – Boussadjra Brahim Sep 25 '20 at 11:39