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

mo3auya's avatar

vite dynamic components import

Hello everyone,

I am migrating an existing laravel ineria from mix to vit.

I did all the steps in the migration guid and everything works fine except for one thing.

I have a component receives a prop conatains an array of components.

I used to require them like this (inside a loop)

....

this.$options.components[component_name] = require(`@/Pages/Components/Inputs/${component_name}`).default

....

this wont wok with vite because of "require"

so I tried these ways and none of them works

this.$options.components[component_name] = () => resolvePageComponent(`./Pages/Components/Inputs/${component_name}.vue`, import.meta.glob('./Pages/**/*.vue'))
this.$options.components[component_name] = () => resolvePageComponent(`@/Pages/Components/Inputs/${component_name}.vue`, import.meta.glob('./Pages/**/*.vue'))
this.$options.components[component_name] = resolvePageComponent(`./Pages/Components/Inputs/${component_name}.vue`, import.meta.glob('./Pages/**/*.vue'))
this.$options.components[component_name] = resolvePageComponent(`@/Pages/Components/Inputs/${component_name}.vue`, import.meta.glob('./Pages/**/*.vue'))

all of them throws the same exception

"Uncaught (in promise) Error: Page not found: ./Pages/Components/Inputs/Text.vue".
0 likes
4 replies
mo3auya's avatar

@Sinnbeck Right, it works fine in the app.js file.

but it does not work in a the component that receives the props

mo3auya's avatar

@Sinnbeck yes, here is idea. this page consists of many components based on the user. And could be build dynamicly. so, instead of importing a 100 component inside this page "I wont use most of them", I used to import only the components that passed to parent component.

1 like

Please or to participate in this conversation.