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?
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With