I created a new project with mix phx.new hello
with
``
erlang 25.3
elixir 1.14.4-otp-25
nodejs 14.5.0
``
in .tool-versions
.
I then created
lib/hello_web/live/dashboard_live/index.ex
defmodule HelloWeb.DashboardLive.Index do
use HelloWeb, :live_view
@impl true
def mount(params, session, socket) do
IO.inspect("Mounting dashboard")
{:ok, socket}
end
end
and lib/hello_web/live_dashboard_live/index.html.heex
<div class="ui container">
<div class="ui basic segment">
<div class="ui stackable grid">
<div class="sixteen wide column">
<p> This is the dashboard </p>
</div>
<div class="two column row">
<p> Here there would be a component </p>
</div>
</div>
</div>
</div>
I also altered the route for “/” to live "/", DashboardLive.Index, :index
.
When I now run the application, I see this in the console:
Compiling 1 file (.ex)
warning: variable "params" is unused (if the variable is not meant to be used, prefix it with an underscore)
lib/hello_web/live/dashboard_live/index.ex:5: HelloWeb.DashboardLive.Index.mount/3
warning: variable "session" is unused (if the variable is not meant to be used, prefix it with an underscore)
lib/hello_web/live/dashboard_live/index.ex:5: HelloWeb.DashboardLive.Index.mount/3
[info] Running HelloWeb.Endpoint with cowboy 2.10.0 at 127.0.0.1:4000 (http)
[info] Access HelloWeb.Endpoint at http://localhost:4000
[watch] build finished, watching for changes...
Browserslist: caniuse-lite is outdated. Please run:
npx update-browserslist-db@latest
Why you should do it regularly: https://github.com/browserslist/update-db#readme
Rebuilding...
Done in 205ms.
warning: variable "params" is unused (if the variable is not meant to be used, prefix it with an underscore)
lib/hello_web/live/dashboard_live/index.ex:5
warning: variable "session" is unused (if the variable is not meant to be used, prefix it with an underscore)
lib/hello_web/live/dashboard_live/index.ex:5
And when I reload the page, I see this:
warning: variable "params" is unused (if the variable is not meant to be used, prefix it with an underscore)
lib/hello_web/live/dashboard_live/index.ex:5
warning: variable "session" is unused (if the variable is not meant to be used, prefix it with an underscore)
lib/hello_web/live/dashboard_live/index.ex:5
[info] GET /
warning: variable "params" is unused (if the variable is not meant to be used, prefix it with an underscore)
lib/hello_web/live/dashboard_live/index.ex:5
warning: variable "session" is unused (if the variable is not meant to be used, prefix it with an underscore)
lib/hello_web/live/dashboard_live/index.ex:5
[debug] Processing with HelloWeb.DashboardLive.Index.index/2
Parameters: %{}
Pipelines: [:browser]
"Mounting dashboard"
[info] Sent 200 in 47ms
warning: variable "params" is unused (if the variable is not meant to be used, prefix it with an underscore)
lib/hello_web/live/dashboard_live/index.ex:5
warning: variable "session" is unused (if the variable is not meant to be used, prefix it with an underscore)
lib/hello_web/live/dashboard_live/index.ex:5
[info] CONNECTED TO Phoenix.LiveView.Socket in 21µs
Transport: :websocket
Serializer: Phoenix.Socket.V2.JSONSerializer
Parameters: %{"_csrf_token" => "EDUxMwYiE2AZCQI5GTg7AyFgEiw3AA1bIBAkBJUTXMOOXhaAt9fkyNX9", "_live_referer" => "undefined", "_mounts" => "0", "_track_static" => %{"0" => "http://localhost:4000/assets/app.css", "1" => "http://localhost:4000/assets/app.js"}, "vsn" => "2.0.0"}
[debug] MOUNT HelloWeb.DashboardLive.Index
Parameters: %{}
Session: %{"_csrf_token" => "YwpXDhF4ADMvAPZBUYtGNNUb"}
"Mounting dashboard"
[debug] Replied in 213µs
warning: variable "params" is unused (if the variable is not meant to be used, prefix it with an underscore)
lib/hello_web/live/dashboard_live/index.ex:5
warning: variable "session" is unused (if the variable is not meant to be used, prefix it with an underscore)
lib/hello_web/live/dashboard_live/index.ex:5
Based on this, it seems like it’s nothing in my project, per se, but something about the environment on my (and others) computers, maybe?
I am running Ubuntu 22.04 (Lenovo X1 Extreme gen 5), and installed Elixir and Erlang with `asdf. In the new project I created, I used elixir 1.14, and the other deps are
[
{:phoenix, "~> 1.7.2"},
{:phoenix_ecto, "~> 4.4"},
{:ecto_sql, "~> 3.6"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 3.3"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:phoenix_live_view, "~> 0.18.16"},
{:floki, ">= 0.30.0", only: :test},
{:phoenix_live_dashboard, "~> 0.7.2"},
{:esbuild, "~> 0.7", runtime: Mix.env() == :dev},
{:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},
{:swoosh, "~> 1.3"},
{:finch, "~> 0.13"},
{:telemetry_metrics, "~> 0.6"},
{:telemetry_poller, "~> 1.0"},
{:gettext, "~> 0.20"},
{:jason, "~> 1.2"},
{:plug_cowboy, "~> 2.5"}
]
Thank you so much for you help (and Elixir in general)!