Application phoenix exited: Phoenix.start(:normal, []) returned an error: shutdown: failed to start child: Phoenix.CodeReloader.Server

I created a test chat with phoenix 1.3.0 and when on the console I try to start the server I get this error:

$ mix phx.server
warning: found quoted keyword “test” but the quotes are not required. Note that keywords are always atoms, even when quoted, and quotes should only be used to introduce keywords with foreign characters in them
mix.exs:57

11:19:41.423 [info] Application phoenix exited: Phoenix.start(:normal, []) returned an error: shutdown: failed to start child: Phoenix.CodeReloader.Server
** (EXIT) an exception was raised:
** (UndefinedFunctionError) function Phoenix.CodeReloader.Server.start_link/0 is undefined (module Phoenix.CodeReloader.Server is not available)
Phoenix.CodeReloader.Server.start_link()
(stdlib) supervisor.erl:379: :supervisor.do_start_child_i/3
(stdlib) supervisor.erl:365: :supervisor.do_start_child/2
(stdlib) supervisor.erl:349: anonymous fn/3 in :supervisor.start_children/2
(stdlib) supervisor.erl:1157: :supervisor.children_map/4
(stdlib) supervisor.erl:315: :supervisor.init_children/2
(stdlib) gen_server.erl:374: :gen_server.init_it/2
(stdlib) gen_server.erl:342: :gen_server.init_it/6
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

11:19:41.426 [info] Application phoenix_pubsub exited: :stopped

11:19:41.426 [info] Application eex exited: :stopped

11:19:41.426 [info] Application poison exited: :stopped

11:19:41.427 [info] Application plug exited: :stopped

11:19:41.427 [info] Application mime exited: :stopped
** (MatchError) no match of right hand side value: {:error, {:phoenix, {{:shutdown, {:failed_to_start_child, Phoenix.CodeReloader.Server, {:EXIT, {:undef, [{Phoenix.CodeReloader.Server, :start_link, [], []}, {:supervisor, :do_start_child_i, 3, [file: ‘supervisor.erl’, line: 379]}, {:supervisor, :do_start_child, 2, [file: ‘supervisor.erl’, line: 365]}, {:supervisor, :"-start_children/2-fun-0-", 3, [file: ‘supervisor.erl’, line: 349]}, {:supervisor, :children_map, 4, [file: ‘supervisor.erl’, line: 1157]}, {:supervisor, :init_children, 2, [file: ‘supervisor.erl’, line: 315]}, {:gen_server, :init_it, 2, [file: ‘gen_server.erl’, line: 374]}, {:gen_server, :init_it, 6, [file: ‘gen_server.erl’, line: 342]}, {:proc_lib, :init_p_do_apply, 3, [file: ‘proc_lib.erl’, line: 249]}]}}}}, {Phoenix, :start, [:normal, []]}}}}
(phoenix) lib/mix/tasks/compile.phoenix.ex:11: Mix.Tasks.Compile.Phoenix.run/1
(mix) lib/mix/task.ex:316: Mix.Task.run_task/3
(mix) lib/mix/tasks/compile.all.ex:68: Mix.Tasks.Compile.All.run_compiler/2
(mix) lib/mix/tasks/compile.all.ex:52: Mix.Tasks.Compile.All.do_compile/4
(mix) lib/mix/tasks/compile.all.ex:23: anonymous fn/1 in Mix.Tasks.Compile.All.run/1
(mix) lib/mix/tasks/compile.all.ex:39: Mix.Tasks.Compile.All.with_logger_app/1
(mix) lib/mix/task.ex:316: Mix.Task.run_task/3
(mix) lib/mix/tasks/compile.ex:94: Mix.Tasks.Compile.run/1
(mix) lib/mix/task.ex:316: Mix.Task.run_task/3
(mix) lib/mix/task.ex:340: Mix.Task.get_task_or_run/3
(mix) lib/mix/task.ex:299: Mix.Task.run_task/3
(mix) lib/mix/cli.ex:79: Mix.CLI.run_task/2
(elixir) lib/code.ex:767: Code.require_file/2

:wave:

Can you show what’s in deps in your mis.exs?

defp deps do
[
{:phoenix, “~> 1.3.0-rc”},
{:phoenix_pubsub, “~> 1.0”},
{:phoenix_ecto, “~> 3.2”},
{:postgrex, “>= 0.0.0”},
{:phoenix_html, “~> 2.10”},
{:phoenix_live_reload, “~> 1.0”, only: :dev},
{:gettext, “~> 0.11”},
{:cowboy, “~> 1.0”}
]
end

Looks fine except for -rc flag for the phoenix version (it can be safely removed, since phoenix 1.3.0 has been released), but that’s probably unrelated.

Can you show what’s in your endpoint.ex?

defmodule Elchat.Endpoint do
  use Phoenix.Endpoint, otp_app: :elchat

  socket "/socket", Elchat.UserSocket

  # Serve at "/" the static files from "priv/static" directory.
  #
  # You should set gzip to true if you are running phoenix.digest
  # when deploying your static files in production.
  plug Plug.Static,
    at: "/", from: :elchat, gzip: false,
    only: ~w(css fonts images js favicon.ico robots.txt)

  # Code reloading can be explicitly enabled under the
  # :code_reloader configuration of your endpoint.
  if code_reloading? do
    socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
    plug Phoenix.LiveReloader
    plug Phoenix.CodeReloader
  end

  plug Plug.RequestId
  plug Plug.Logger

  plug Plug.Parsers,
    parsers: [:urlencoded, :multipart, :json],
    pass: ["*/*"],
    json_decoder: Poison

  plug Plug.MethodOverride
  plug Plug.Head

  # The session will be stored in the cookie and signed,
  # this means its contents can be read but not tampered with.
  # Set :encryption_salt if you would also like to encrypt it.
  plug Plug.Session,
    store: :cookie,
    key: "_elchat_key",
    signing_salt: "Yg8j+AHA"

  plug Elchat.Router
end

You’re using an ancient version of Phoenix for some reason, maybe your phoenix installer is out of date?

@benwilson512 My version are Phoenix v1.3.4

What command do you use to start the server?

@idi527 I used mix phx.server and show this error:

13:58:15.788 [info]  Application phoenix exited: Phoenix.start(:normal, []) returned an error: shutdown: failed to start child: Phoenix.CodeReloader.Server
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function Phoenix.CodeReloader.Server.start_link/0 is undefined (module Phoenix.CodeReloader.Server is not available)
            Phoenix.CodeReloader.Server.start_link()
            (stdlib) supervisor.erl:379: :supervisor.do_start_child_i/3
            (stdlib) supervisor.erl:365: :supervisor.do_start_child/2
            (stdlib) supervisor.erl:349: anonymous fn/3 in :supervisor.start_children/2
            (stdlib) supervisor.erl:1157: :supervisor.children_map/4
            (stdlib) supervisor.erl:315: :supervisor.init_children/2
            (stdlib) gen_server.erl:374: :gen_server.init_it/2
            (stdlib) gen_server.erl:342: :gen_server.init_it/6
            (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

13:58:15.790 [info]  Application phoenix_pubsub exited: :stopped

13:58:15.790 [info]  Application eex exited: :stopped

13:58:15.790 [info]  Application poison exited: :stopped

13:58:15.791 [info]  Application plug exited: :stopped

13:58:15.791 [info]  Application mime exited: :stopped
** (MatchError) no match of right hand side value: {:error, {:phoenix, {{:shutdown, {:failed_to_start_child, Phoenix.CodeReloader.Server, {:EXIT, {:undef, [{Phoenix.CodeReloader.Server, :start_link, [], []}, {:supervisor, :do_start_child_i, 3, [file: 'supervisor.erl', line: 379]}, {:supervisor, :do_start_child, 2, [file: 'supervisor.erl', line: 365]}, {:supervisor, :"-start_children/2-fun-0-", 3, [file: 'supervisor.erl', line: 349]}, {:supervisor, :children_map, 4, [file: 'supervisor.erl', line: 1157]}, {:supervisor, :init_children, 2, [file: 'supervisor.erl', line: 315]}, {:gen_server, :init_it, 2, [file: 'gen_server.erl', line: 374]}, {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 342]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}}}}, {Phoenix, :start, [:normal, []]}}}}
    (phoenix) lib/mix/tasks/compile.phoenix.ex:11: Mix.Tasks.Compile.Phoenix.run/1
    (mix) lib/mix/task.ex:316: Mix.Task.run_task/3
    (mix) lib/mix/tasks/compile.all.ex:68: Mix.Tasks.Compile.All.run_compiler/2
    (mix) lib/mix/tasks/compile.all.ex:52: Mix.Tasks.Compile.All.do_compile/4
    (mix) lib/mix/tasks/compile.all.ex:23: anonymous fn/1 in Mix.Tasks.Compile.All.run/1
    (mix) lib/mix/tasks/compile.all.ex:39: Mix.Tasks.Compile.All.with_logger_app/1
    (mix) lib/mix/task.ex:316: Mix.Task.run_task/3
    (mix) lib/mix/tasks/compile.ex:94: Mix.Tasks.Compile.run/1
    (mix) lib/mix/task.ex:316: Mix.Task.run_task/3
    (mix) lib/mix/task.ex:340: Mix.Task.get_task_or_run/3
    (mix) lib/mix/task.ex:299: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:79: Mix.CLI.run_task/2
    (elixir) lib/code.ex:767: Code.require_file/2

i changed the version of phoenix in mix.ex, from 1.3.0 to 1.3.4

Does the same error happen in a “fresh” phoenix project (mix phx.new ...)? Can you publish the project (or a reproducible example) on github?

1 Like

in fact, I surrounded the phx.new mix and after opening the new project I saw that even the structure was different.

@idi527 and @benwilson512 thanks very much friends, I recreated the app and worked all right

1 Like