Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Error when importing a component / layout

Hello,

I have an error when importing a component / layout.

import Layout from './Layout'

Here is the error.

/* unplugin-vue-components disabled */
...
[plugin:vite:import-analysis] Failed to resolve import "./Layout" from "resources/js/Pages/AboutComponent.vue". Does the file exist?

Vite seems not to resolve correctly the path to retrieve the component. But the problem is perhaps not with Vite, I really don't know.

I just began discovering InertiaJS and Vite, so I don't have any experience with these technologies.

I have tried this to solve the problem, but nothing works.

import Layout from '@/Layout'
import Layout from 'absolute_path_to_layout'

Can you help me please ?

Thanks a lot.

Vincent

0 likes
16 replies
Sinnbeck's avatar

Show your vite config and the absolute path to the file

1 like
vincent15000's avatar

@Sinnbeck

Vite config

export default defineConfig({
    plugins: [
        laravel([
            'resources/css/app.scss',
            'resources/js/app.js',
        ]),
        vue({
            template: {
                transformAssetUrls: {
                    // The Vue plugin will re-write asset URLs, when referenced
                    // in Single File Components, to point to the Laravel web
                    // server. Setting this to `null` allows the Laravel plugin
                    // to instead re-write asset URLs to point to the Vite
                    // server instead.
                    base: null,
 
                    // The Vue plugin will parse absolute URLs and treat them
                    // as absolute paths to files on disk. Setting this to
                    // `false` will leave absolute URLs un-touched so they can
                    // reference assets in the public directly as expected.
                    includeAbsolute: false,
                },
            },
        }),
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        }),
    ],
});

Absolute path to the Layout file

/home/vincent/Documents/PRO/DEVELOPPEMENT/mentoring/resources/js/Layout.vue
vincent15000's avatar

@Sinnbeck I have already tried this too ... The error message shows an arrow pointing on the first character inside the brackets, ie the first dot.

import Layout from './Layout'
                    ^
...
import Layout from '../Layout'
                    ^
vincent15000's avatar

@Sinnbeck Here it is.

[plugin:vite:import-analysis] Failed to resolve import "../Layout" from "resources/js/Pages/AboutComponent.vue". Does the file exist?
/home/vincent/Documents/PRO/DEVELOPPEMENT/mentoring/resources/js/Pages/AboutComponent.vue:3:23
1  |  /* unplugin-vue-components disabled */
2  |  
3  |    import Layout from '../Layout'
   |                        ^
4  |  
5  |  	const _sfc_main = {
    at formatError (/home/vincent/Documents/PRO/DEVELOPPEMENT/mentoring/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:39080:46)
    at TransformContext.error (/home/vincent/Documents/PRO/DEVELOPPEMENT/mentoring/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:39076:19)
    at normalizeUrl (/home/vincent/Documents/PRO/DEVELOPPEMENT/mentoring/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:58354:26)
    at async TransformContext.transform (/home/vincent/Documents/PRO/DEVELOPPEMENT/mentoring/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:58503:57)
    at async Object.transform (/home/vincent/Documents/PRO/DEVELOPPEMENT/mentoring/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:39317:30)
    at async doTransform (/home/vincent/Documents/PRO/DEVELOPPEMENT/mentoring/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:50037:29
Click outside or fix the code to dismiss.
You can also disable this overlay by setting server.hmr.overlay to false in vite.config.js.
vincent15000's avatar

@Sinnbeck And here is the JS to create the inertia app.

createInertiaApp({
  resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
  setup({ el, App, props, plugin }) {
    const app = createApp({ render: () => h(App, props) })
      .component("font-awesome-icon", FontAwesomeIcon)
      .mount(el)
  },
});
vincent15000's avatar

@Sinnbeck That works with the .vue extension. In the documentation it's not showed with the extension. What does this mean ? Why this error without the extension ? I thought that the extension was automatically detected.

2 likes
Sinnbeck's avatar

@vincent15000 which guide? Perhaps it uses mix which might pick it up automatically (pretty sure it goes does)

1 like
Sinnbeck's avatar

@dev-mike I suggest making your own thread explaining your exact problem :)

1 like
DryerLintPurple's avatar

A year later and it looks like the Inertia docs haven't changed any. In addition to using import Layout from '../Layout.vue' as mentioned above, make sure that the createInertiaApp block your app.js file is using the resolvePageComponent helper. See "Vite compatible imports" on the Laravel Vite plugin upgrade docs. (I'd link it but the spam filter on here won't let me.)

1 like

Please or to participate in this conversation.