Uncaught SyntaxError: The requested module '/node_modules/.vite/vue.js?v=535663ae' does not provide an export named 'default'

Uncaught SyntaxError: The requested module '/node_modules/.vite/vue.js?v=535663ae' does not provide an export named 'default'

我正在使用一个名为 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' 导入默认导出。

// some ts file
import Vue from "vue";

// the module
export default {}

如果应该有一个名为 'Vue' 的命名导出,您应该这样写:import { Vue } from 'vue'

参考文献:

我认为您正在使用 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