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

DavidSpooner's avatar

Has anyone gotten Inertia+Svelte to work with Laravel 9 and Vite?

The Inertia JS documentation shows the setup for Inertia+Svelte with Vite here: https://inertiajs.com/client-side-setup

However, the vite configuration presumably also requires that you set up both a vite-laravel adapter and a vite-svelte adapter. These are the two official adapters: "@sveltejs/vite-plugin-svelte" and "laravel-vite-plugin".

However, I have not been able to get "@sveltejs/vite-plugin-svelte" to work without setting "type": "module" in package.json. That is presumably fine, but setting "type": "module" in package.json breaks "laravel-vite-plugin". That seems to be a bug with an associated Draft PR here: https://github.com/laravel/vite-plugin/pull/189

From what I have been able to tell, this scenario completely eliminates the possibility of setting up Inertia+Svelte with Vite in Laravel. Since Vite is the default asset bundler for Laravel, I would recommend at least a warning about this scenario in the Inertia Js Documentation and in the Laravel documentation regarding Inertia until the issue is resolved.

What do you all think?

0 likes
6 replies
Devign's avatar

I have successfully used the setup from this repo to get inertia + svelte + vite working.

github.com/tabayomi/laravel-svelte-inertia

1 like
DavidSpooner's avatar

@Devign Thank you for your response. I haven't had a chance to try the code in that repository myself, but assuming that it does work, I guess it would be due to the versioning of Vite and the use of the "vite-plugin-laravel" package instead of the official "laravel-vite-plugin" package.

We are currently on version 4 of Vite, so I would prefer not rolling back 2 whole major versions to 2.x in order to get this thing working.

Also if you look at the "vite-plugin-laravel" repo here: https://github.com/innocenzi/laravel-vite#readme the recommendation is to migrate to the official "laravel-vite-plugin" now.

My guess is that, at least for those of us who want to use the official plugin, we are all just stuck waiting on this PR to get finished and added https://github.com/laravel/vite-plugin/pull/189.

That is, unless someone knows of some other work around like some trick to get "@sveltejs/vite-plugin-svelte" to work without setting "type"="module" in package.json.

NickNY's avatar

@Devign and @davidspooner

You can just add "type": "module" to your own package.json and that should do the trick. I am using the latest versions of Vite + Laravel + Svelte right now, happy to share all of my configs.

1 like
Sinnbeck's avatar

@NickNY I tried this myself but it didnt work with the laravel vite plugin. Perhaps you can show your vite.config.js for how you got that working?

1 like

Please or to participate in this conversation.