Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LiveReloading chapter: server fails to start #2

Open
belgoros opened this issue Apr 20, 2020 · 7 comments
Open

LiveReloading chapter: server fails to start #2

belgoros opened this issue Apr 20, 2020 · 7 comments

Comments

@belgoros
Copy link

belgoros commented Apr 20, 2020

I followed the Pluralsight course and was stopped in the Live Reloading chapter where you starter the Phoenix server:
Screenshot 2020-04-20 at 15 19 26

The dips.exs file in rsvp_web app looks like that:

defp deps do
    [
      {:phoenix, "~> 1.4.16"},
      {:phoenix_pubsub, "~> 1.1"},
      {:phoenix_html, "~> 2.11"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:gettext, "~> 0.11"},
      {:jason, "~> 1.0"},
      {:plug_cowboy, "~> 2.0"}
    ]
  end

Running mix dips.get on the project root didn't solve the problem.

Are there any updates regarding this issue?
I'm using Elixir 1.10.2 and phoenix, "~> 1.4.16 versions at macOS.

@taylonr
Copy link
Owner

taylonr commented Apr 20, 2020 via email

@belgoros
Copy link
Author

belgoros commented Apr 21, 2020

Here are the steps I followed during the cource and the errors raised when executing the requested commands:

  • mix new rsvp_umbrella --umbrella, - OK
  • cd rsvp_umbrella/apps, - OK
  • mix new rsvp --sup, - OK
  • mix phoenix.new rsvp_web --no-ecto, - FAILS with:
    ** (Mix) The task "phoenix.new" could not be found
    Note no mix.exs was found in the current directory
    
    It seems like the right task to run for the latest Phoenix version (1.4.16) would be:
    mix phx.new.web rsvp_web --no-ecto
    

Screenshot 2020-04-21 at 10 54 10

  • so run mix phx.new.web rsvp_web --no-ecto: OK
  • add ecto, postgrex to rsvp/mix.exs. file
  • cd to rsvp_umbrella and run mix deps.get to install dependencies
  • create a new config.exs in rsvp/config folder (it DID NOT EXIST)
  • add the missing import Config in the top of the file, followed by the database settings:
config :rsvp, Rsvp.Repo,
  adapter: Ecto.Adapters.Postgres,
  database: "rsvp",
  username: "postgres",
  password: "postgres"
  • create repo.ex in rsvp/lib folder with the following content:
defmodule Rsvp.Repo do
  use Ecto.Repo, otp_app: :rsvp
end
  • move repo.ex to the rsvp/lib/rsvp folder to respect the module naming structure
  • add ecto repos to the rsvp/config/config.exs file:
config :rsvp, ecto_repos: [Rsvp.Repo]
  • declare children in rsvp/lib/rsvp.ex- FAILS, because the RIGHT file to be update is rsvp/lib/rsvp/application.ex (correct me if I'm wrong):
defmodule Rsvp.Application do
  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  @moduledoc false

  use Application

  def start(_type, _args) do
    children = [
      # Starts a worker by calling: Rsvp.Worker.start_link(arg)
      # {Rsvp.Worker, arg}
      worker(Rsvp.Repo, [])
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: Rsvp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end
  • cd to rsvp_umbrella and run mix compile, - FAILS, you will get an error:
rsvp_umbrella git:(master) mix compile
==> rsvp
Compiling 2 files (.ex)

== Compilation error in file lib/rsvp/application.ex ==
** (CompileError) lib/rsvp/application.ex:12: undefined function worker/2
    (elixir 1.10.2) src/elixir_locals.erl:114: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3
    (stdlib 3.12) erl_eval.erl:680: :erl_eval.do_apply/6

It seems like the error comes from calling worker(Rsvp.Repo, []).

  • Changing the children as follows:
def start(_type, _args) do
    children = [
      # Starts a worker by calling: Rsvp.Worker.start_link(arg)
      # {Rsvp.Worker, arg}
      {Rsvp.Repo, []}
    ]
...

and running mix compile raised another error coming this time from Rsvp.Repo module:

== Compilation error in file lib/rsvp/repo.ex ==
** (ArgumentError) missing :adapter option on use Ecto.Repo
    lib/ecto/repo/supervisor.ex:66: Ecto.Repo.Supervisor.compile_config/2
    lib/rsvp/repo.ex:2: (module)
    (stdlib 3.12) erl_eval.erl:680: :erl_eval.do_apply/6

What is the right way to declare a worker at this step?
What am I missing here?

@taylonr
Copy link
Owner

taylonr commented Apr 21, 2020

Ah, it could be the difference between latest Phoenix (1.4) and the version the course used (1.2)

The course came out right before 1.3, where some of the changes occurred, including umbrella projects and the change from mix phoenix.new to mix phx.new. However, the structural changes were incorporated in the course, but the mix commands were not.

And I'd guess other projects like Ecto etc have made breaking changes in 1.3 or 1.4 compared to 1.2 and that's why you're seeing things like missing an :adapter atom on Ecto.Repo

@belgoros
Copy link
Author

Ok, thank you for your feedback. It's so disappointing to see most of Elixir/Phoenix courses not to updating their content... By chance, Pluralsight offered a FREE month subscription for April 2020 due to COVID-19. So it would even more frustrating to pay money for something outdated...

@taylonr
Copy link
Owner

taylonr commented Apr 21, 2020 via email

@taylonr
Copy link
Owner

taylonr commented Apr 21, 2020

That said, I do understand the frustration of something not working out of the box when you're following along.

I'll take a look and see what all needs to be updated in the course.

@belgoros
Copy link
Author

Oh, that would be really awesome 👍 , thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants