Module not found: Error: Can't resolve './router'| Vue router

Module not found: Error: Can't resolve './router'| Vue router

在 search.js 来自这个文件:

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

import SearchIndex from './components/omdb/SearchIndex.vue'

const routes = [
    {
        path: '/',
        name: 'welcome',
        component: SearchIndex
    },
]

export default createRouter({
    history: createWebHistory(),
    routes
})

在 app.js 来自这个文件:

require('./bootstrap');

require('alpinejs');

import { createApp } from "vue";
import router from './router'
import SearchIndex from './components/omdb/SearchIndex'


createApp({
    components:{
        SearchIndex
    }
}).use(router).mount('#app')

这个错误:

ERROR in ./resources/js/app.js 6:0-30
Module not found: Error: Can't resolve './router' in 'D:\xampp\htdocs\omdb\resources\js'

我不明白为什么它会给我这个错误。我的文件结构如下:

import router from './router' 中的模块路径解析为 ./router.js./router/index.js。这两个文件都不存在,导致您观察到的错误。

您可以将 ./router/search.js 重命名为 ./router/index.js,或者直接导入 ./router/search.js 文件:

import router from './router/search'