The error you're encountering, Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'default'), typically occurs when the module you're trying to import does not have a default export. This can happen if the module is using named exports instead.
Here are a few steps to troubleshoot and resolve this issue:
-
Check the Exports in Your Vue Components: Ensure that your Vue components are using default exports. For example:
// resources/assets/js/Pages/Campaigns/EditCategories.vue export default { // component options } -
Update the
resolvePageComponentFunction: TheresolvePageComponentfunction should correctly handle the dynamic imports. Ensure that it correctly resolves the component and handles the default export. Here’s an updated version of yourcreateInertiaAppsetup:import { createApp, h } from 'vue'; import { createInertiaApp, InertiaProgress } from '@inertiajs/vue3'; import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'; InertiaProgress.init(); createInertiaApp({ resolve: (name) => { const pages = import.meta.glob('./Pages/Campaigns/**/*.vue'); const importPage = pages[`./Pages/Campaigns/${name}.vue`]; if (!importPage) { throw new Error(`Page not found: ${name}`); } return importPage().then(module => module.default || module); }, setup({ el, App, props, plugin }) { createApp({ render: () => h(App, props) }) .use(plugin) .mount(el); }, }); -
Ensure Correct File Paths: Verify that the paths you are using in
import.meta.globare correct and match the actual file structure. For example, if your files are located inModules/Admin/resources/assets/js/Pages/Campaigns, you should use:import.meta.glob('./Modules/Admin/resources/assets/js/Pages/Campaigns/**/*.vue') -
Check for Typos and Case Sensitivity: Ensure there are no typos in your file paths and that the case sensitivity matches exactly with your file system.
-
Debugging: Add some console logs to debug the resolved paths and ensure they are correct:
createInertiaApp({ resolve: (name) => { const pages = import.meta.glob('./Pages/Campaigns/**/*.vue'); console.log('Available pages:', pages); const importPage = pages[`./Pages/Campaigns/${name}.vue`]; if (!importPage) { throw new Error(`Page not found: ${name}`); } return importPage().then(module => { console.log('Resolved module:', module); return module.default || module; }); }, setup({ el, App, props, plugin }) { createApp({ render: () => h(App, props) }) .use(plugin) .mount(el); }, });
By following these steps, you should be able to resolve the issue with the dynamic imports and ensure that your Vue components are correctly loaded.