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

15,125

Solution 1

Vue v3:

import * as Vue from 'vue';
import * as VueRouter from 'vue-router';

const routes = [
  // TODO
];

const router = VueRouter.createRouter({
  history: VueRouter.createWebHistory(),
  routes,
});

Vue.createApp(App).use(router).mount('#app');

https://next.router.vuejs.org/guide/migration/index.html

Solution 2

Make sure all dependencies installed.

eg. install the router

npm install vue-router@next --save

Solution 3

When you upgrade to vue v3 should upgrade vue-router to 'vue-router/next' Offical website and use this code instead to import the function

import { createRouter, createWebHistory } from 'vue-router'

and remove

Vue.use(VueRouter);
Share:
15,125
cypher
Author by

cypher

Updated on July 22, 2022

Comments

  • cypher
    cypher almost 2 years

    I am new with this vue and I got this error when I try to run (npm run serve):

    ***WARNING Compiled with 4 warnings
    warning in ./src/main.js
    "export 'default' (imported as 'Vue') was not found in 'vue'
    warning in ./src/main.js
    "export 'default' (imported as 'Vue') was not found in 'vue'
    warning in ./src/main.js
    "export 'default' (imported as 'Vue') was not found in 'vue'
    warning in ./src/router/index.js
    "export 'default' (imported as 'Vue') was not found in 'vue'
    

    App running at:

    index.js

    import Vue from "vue";
    import VueRouter from "vue-router";
    import Home from "../views/Home.vue";
    Vue.use(VueRouter);
    const routes = [{
            path: "/home",
            name: "home",
            component: Home,
            meta: {
                requiresAuth: true
            }
        },
        {
            path: "/",
            name: "login",
            component: () =>
                import ("../views/login.vue")
        },
        {
            path: "/register",
            name: "register",
            component: () =>
                import ("../views/register.vue")
        }
    ];
    const router = new VueRouter({
        mode: "history",
        base: process.env.BASE_URL,
        routes
    });
    router.beforeEach((to, from, next) => {
        if (to.matched.some(record => record.meta.requiresAuth)) {
            if (localStorage.getItem("jwt") == null) {
                next({
                    path: "/"
                });
            } else {
                next();
            }
        } else {
            next();
        }
    });
    export default router;
    

    main.js

    import Vue from "vue";
    import App from "./App.vue";
    import router from "./router";
    import axios from "axios";
    import "bootstrap/dist/css/bootstrap.css";
    
    const base = axios.create({
        baseURL: "http://localhost:4000"
    });
    
    Vue.prototype.$http = base;
    Vue.config.productionTip = false;
    new Vue({
        router,
        render: h => h(App)
    }).$mount("#app");