Phoenix app not starting because of Cowboy error

I’m learning phoenix live view and while trying to run my project I get this error:

[info] Application teppelin exited: Teppelin.Application.start(:normal, []) returned an error: shutdown: failed to start child: TeppelinWeb.Endpoint
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function Plug.Cowboy.child_spec/1 is undefined (module Plug.Cowboy is not available)
            Plug.Cowboy.child_spec([scheme: :http, plug: {TeppelinWeb.Endpoint, []}, options: [dispatch: [_: [{:_, Phoenix.Endpoint.Cowboy2Handler, {TeppelinWeb.Endpoint, []}}]], port: 4000, otp_app: :teppelin]])
            (phoenix) lib/phoenix/endpoint/cowboy2_adapter.ex:44: Phoenix.Endpoint.Cowboy2Adapter.child_spec/3
            (phoenix) lib/phoenix/endpoint/supervisor.ex:108: anonymous fn/6 in Phoenix.Endpoint.Supervisor.server_children/4
            (elixir) lib/enum.ex:1948: Enum."-reduce/3-lists^foldl/2-0-"/3
            (phoenix) lib/phoenix/endpoint/supervisor.ex:99: Phoenix.Endpoint.Supervisor.server_children/4
            (phoenix) lib/phoenix/endpoint/supervisor.ex:59: Phoenix.Endpoint.Supervisor.init/1
            (stdlib) supervisor.erl:295: :supervisor.init/1
            (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

I already tried switching from cowboy to plug_cowboy but it didn’t work. This is my deps function:

defp deps do
    [
      {:phoenix, "~> 1.4.9"},
      {:phoenix_pubsub, "~> 1.0"},
      {:phoenix_html, "~> 2.10"},
      {:phoenix_live_reload, "~> 1.2",  only: :dev},
      {:gettext, "~> 0.11"},
      # {:cowboy, "~> 2.0"},
      {:plug_cowboy, "~> 2.1"},
      {:phoenix_live_view, "~> 0.3.1"},
      {:poison, "~> 4.0"},
      {:httpoison, "~> 1.5.0"},
    ]
  end

Ok, so I think I figured it out.
I had to delete the locked mix file, delete the _build folder and then mix deps.get && mix deps.compile.
And the error went away

3 Likes

I got a similar error when attempting to run mix phx.server – I think it was after I tried running the bleeding edge GitHub version of phoenix_live_view in my project.

** (Mix) Could not start application remit: Remit.Application.start(:normal, ) returned an error: shutdown: failed to start child: RemitWeb.Endpoint
** (EXIT) an exception was raised:
** (UndefinedFunctionError) function Phoenix.Endpoint.Cowboy2Adapter.child_specs/2 is undefined (module Phoenix.Endpoint.Cowboy2Adapter is not available)

mix deps.get && mix deps.compile

gave me

could not compile dependency :phoenix, “mix compile” failed. You can recompile this dependency with “mix deps.compile phoenix”, update it with “mix deps.update phoenix” or clean it with “mix deps.clean phoenix”

so I did

mix deps.clean phoenix && mix deps.get

and then it worked. I suspect some subset of those commands would have been enough – perhaps just the last one, without attempting to compile?

1 Like