Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'does not provide an export named 'createRouter'' vue 3, vite and vue-router

I just started using vite with vue.

When I'm trying to use vue-router I get the error:

SyntaxError: The requested module '/node_modules/.vite/vue-router/dist/vue-router.esm.js?v=4830dca4' does not provide an export named 'createRouter

My router/index.js looks like this:

import {
 createWebHistory,
 createRouter
} from "vue-router";

import Services from "../views/Services.vue";
import Customers from "../views/Customers.vue";

const history = createWebHistory();
const routes = [
  {
    path: "/",
    component: Services
  },
  {
    path: "/customers",
    component: Customers
  },
];
const router = createRouter({
  history,
  routes
});
export default router;

My main.js looks like this:

import { createApp } from 'vue'
import App from './App.vue'
import './index.css'
import router from './router'

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

My package.json looks like this:

{
 "name": "frontend",
 "version": "0.0.0",
 "scripts": {
 "dev": "vite",
 "build": "vite build"
},
 "dependencies": {
 "vue": "^3.0.5",
 "vue-router": "^3.4.9"
},
 "devDependencies": {
 "@vitejs/plugin-vue": "^1.0.4",
 "@vue/compiler-sfc": "^3.0.5",
 "autoprefixer": "^10.2.3",
 "postcss": "^8.2.4",
 "tailwindcss": "^2.0.2",
 "vite": "^2.0.0-beta.12"
 }
}

Anyone knows how to export the route?

like image 756
Maiken Madsen Avatar asked Jan 23 '21 11:01

Maiken Madsen


1 Answers

if you check inside the file '/node_modules/.vite/vue-router/dist/vue-router.esm.js?v=4830dca4'

there is no export default syntax. only named export {}

so instead import default, use named import.

// don't
import VueRouter from 'vue-router'

// do
import { createRouter, createWebHashHistory } from 'vue-router'
like image 65
kubido Avatar answered Sep 20 '22 07:09

kubido