sreyansjain

sreyansjain

Can someone please explain how to get inertiajs running with svelte5 and phoenix. Just a Hello World

Hello,

I want to test inertiajs and svelte5. I have been doing liveview for years now, but I have no experience with client side frameworks like svelte, react, vue etc.

The tooling (esbuild) is really difficult to set up for me.
I am trying to follow the instructions in Inertiajs but then i get the error import.meta is not defined.

I am trying to setup esbuild script and sometimes i get import_meta not available in iife. I set the format to esm, then the thing compiles but no response in the web page. It gives some module export kind of error which I fail to understand.

Can someone be so kind to just mention the steps to get a fresh install of phoenix, inertiajs and svelte5 working. Just a hello world would be enough.

Thank you so so much.

PS. I tried following - GitHub - tonydangblog/phoenix-inertia-svelte: A guide and example project…, but get the above errors.

Most Liked

skyturtle

skyturtle

Hey,

I’ve got an example app with Phoenix, Inertia.js v2, and Svelte 5. Here’s the repo and it’s deployed at https://svelix.skyturtle.io/ using Coolify.

Without seeing your code, it’s hard to say what the issue might be. But from your example of import_meta not available..., it sounds like you may be using code examples that were meant for Vite, which a lot of JavaScript tooling and frameworks are geared towards.

I used the repo you linked as an example as well. The app.js and build.js were incredibly helpful (thanks @tonydang !). That project used Inertia v1 so I had to make some tweaks, but it’s fairly similar. I also have serverOpts, but I haven’t been able to get SSR working yet. Client-side rendering works fine though.

One thing you will notice in my build.js is conditions: ['svelte'],. I have no idea what this actually does, but it was the only way I could get the assets to build in development and on deployment. I’ve tried reading the docs several times, but I still don’t understand what exactly it does. If any one knows, I’m all ears.

I definitely understand your frustrations with the tooling. I hit roadblocks building and deploying assets with error messages that were hard to figure out. I see why the Phoenix team made the move to an esbuild wrapper. Unfortunately, Svelte requires an esbuild plugin, which is not supported by the wrapper. I actually built the same app using React instead of Svelte. esbuild has built in support for JSX so you can use the esbuild wrapper (as they do in the Inertia.js Phoenix adapter docs). Building and deploying that app was much simpler.

The README has some additional details. I’m still updating it as I make changes, but I think it will be enough to get you started. Hope that helps!

ravecat

ravecat

@skyturtle thank you very much for your example, it helped clarify some issues. phoenix 1.8 required a small change, I have put it as an example in the repository

unfortunately SSR still doesn’t work. did you find a solution?

ravecat

ravecat

@skyturtle transfer Phoenix + Inertia projects to vite thanks to a project from this topic. I’ll leave an example in repository for the future. SSR is still a work in progress, but I’m quite happy with the current result

Where Next?

Popular in Questions Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement