(UndefinedFunctionError) function :ranch.child_spec/6 is undefined (module :ranch is not available)

I installed elixir and erlang using asdf package manager
I installed elixir 1.6.4 and erlang 20 and make them global.
in my phoenix project, I couldn’t start phoenix server.
I am getting this error.

[info] Application texting exited: Texting.Application.start(:normal, []) returned an error: shutdown: failed to start child: TextingWeb.Endpoint
    ** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
        ** (EXIT) an exception was raised:
            ** (UndefinedFunctionError) function :ranch.child_spec/6 is undefined (module :ranch is not available)
                (ranch) :ranch.child_spec(TextingWeb.Endpoint.HTTP, 100, :ranch_tcp, [max_connections: 16384, port: 4000], :cowboy_protocol, [env: [dispatch: [{:_, [], [{["phoenix", "live_reload", "socket", "longpoll"], [], Plug.Adapters.Cowboy.Handler, {Phoenix.Transports.LongPoll, {TextingWeb.Endpoint, Phoenix.LiveReloader.Socket, :longpoll}}}, {["phoenix", "live_reload", "socket", "websocket"], [], Phoenix.Endpoint.CowboyWebSocket, {Phoenix.Transports.WebSocket, {TextingWeb.Endpoint, Phoenix.LiveReloader.Socket, :websocket}}}, {["socket", "websocket"], [], Phoenix.Endpoint.CowboyWebSocket, {Phoenix.Transports.WebSocket, {TextingWeb.Endpoint, TextingWeb.UserSocket, :websocket}}}, {:_, [], Plug.Adapters.Cowboy.Handler, {TextingWeb.Endpoint, []}}]}]], onresponse: #Function<1.69669231/4 in Plug.Adapters.Cowboy.add_on_response/3>])
                (phoenix) lib/phoenix/endpoint/cowboy_handler.ex:81: Phoenix.Endpoint.CowboyHandler.child_spec/3
                (phoenix) lib/phoenix/endpoint/handler.ex:33: anonymous fn/5 in Phoenix.Endpoint.Handler.init/1
                (elixir) lib/enum.ex:1899: Enum."-reduce/3-lists^foldl/2-0-"/3
                (phoenix) lib/phoenix/endpoint/handler.ex:31: Phoenix.Endpoint.Handler.init/1
                (stdlib) supervisor.erl:294: :supervisor.init/1
                (stdlib) gen_server.erl:365: :gen_server.init_it/2
                (stdlib) gen_server.erl:333: :gen_server.init_it/6
                (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3

What am I missing here?

This usually means ranch .beam files failed to compile correctly.

Try removing your _build folder and compiling again?

1 Like