未捕获语法错误:请求的模块'/node_modules/.vite/vue.js?v=535663ae'未提供名为'Default'的导出

2022-03-28 00:00:00 vue.js vue-router

我使用的是名为griptape的js框架(用于区块链)。尝试使用VUE路由器时出现此错误。

import Vue from "vue"; //Error **does not provide an export named 'default'**
import VueRouter from "vue-router";
import Home from "../views/Home.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home,
  },
  {
    path: "/about",
    name: "About",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/About.vue"),
  },
];

 const router = new VueRouter({
  routes,
});
export default router;

而我的vue.d.ts文件如下

import { CompilerOptions } from '@vue/compiler-dom';
import { RenderFunction } from '@vue/runtime-dom';

export declare function compile(template: string | HTMLElement, options?: CompilerOptions): RenderFunction;

export * from "@vue/runtime-dom";

export { }

router.d.ts文件如下


解决方案

我认为您正在使用Vue 3。您应该检查您的vue-router版本。如果您现在只运行npm i vue-router,则版本应为";^3.5.3";。请尝试使用npm i vue-router@next安装较新版本。

然后按如下方式导出路由器:

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

const routes = [
    {
        path:'/',
        name:"Home",
        component:()=>import('./pages/Home.vue')
    }
    ,
    {
        path:'/about',
        name:"About",
        component:()=>import('./pages/About.vue')
    }
]

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

export default router

相关文章