Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
9
Help us understand the problem. What is going on with this article?
@Yoosuke

Phoenix 最初の第一歩 Mix phx.serverでerrorの解決方法

More than 1 year has passed since last update.

mix phx.server が急にerrorを出し始めた時の解決方法

対象者

2018.10.23近辺でPhoenixのチュートリアルにて学習開始し始めた初学者向け

なぜ書くのか?

Phoenixの公式ドキュメントと、フレームワークの構成が変更中の差分が発生している時に起こり得る初学者が辛い時期の差分解決としてのメモ

Up and Runningで学習し始めで事件は起きた!

Start your Phoenix app with:

    $ 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

warning: please add the following dependency to your mix.exs:

    {:plug_cowboy, "~> 1.0"}

This dependency is required by Plug.Adapters.Cowboy
which you may be using directly or indirectly.
Note you no longer need to depend on :cowboy directly.

  (plug) lib/plug/adapters/cowboy.ex:44: Plug.Adapters.Cowboy.warn_and_raise/0
  (plug) lib/plug/adapters/cowboy.ex:29: Plug.Adapters.Cowboy.child_spec/4
  (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:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
  (phoenix) lib/phoenix/endpoint/handler.ex:31: Phoenix.Endpoint.Handler.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

[info] Application hello_app exited: HelloApp.Application.start(:normal, []) returned an error: shutdown: failed to start child: HelloAppWeb.Endpoint
    ** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
        ** (EXIT) an exception was raised:
            ** (RuntimeError) plug_cowboy dependency missing
                (plug) lib/plug/adapters/cowboy.ex:54: Plug.Adapters.Cowboy.warn_and_raise/0
                (plug) lib/plug/adapters/cowboy.ex:29: Plug.Adapters.Cowboy.child_spec/4
                (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:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
                (phoenix) lib/phoenix/endpoint/handler.ex:31: Phoenix.Endpoint.Handler.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
** (Mix) Could not start application hello_app: HelloApp.Application.start(:normal, []) returned an error: shutdown: failed to start child: HelloAppWeb.Endpoint
    ** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
        ** (EXIT) an exception was raised:
            ** (RuntimeError) plug_cowboy dependency missing
                (plug) lib/plug/adapters/cowboy.ex:54: Plug.Adapters.Cowboy.warn_and_raise/0
                (plug) lib/plug/adapters/cowboy.ex:29: Plug.Adapters.Cowboy.child_spec/4
                (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:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
                (phoenix) lib/phoenix/endpoint/handler.ex:31: Phoenix.Endpoint.Handler.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
  • mix.exsファイルに{:plug_cowboy, "~> 1.0"}を追加しろと記載あるので追加する
  • ちなみに、mix.exsは作成されたフォルダの1階層目にある
README.md   assets      deps        mix.exs     priv
_build      config      lib     mix.lock    test
  • mix.exsファイル内の以下の場所に追加

Befor

# Type `mix help deps` for examples and options.
  defp deps do
    [
      {:phoenix, "~> 1.3.4"},
      {: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

After

# Type `mix help deps` for examples and options.
  defp deps do
    [
      {:phoenix, "~> 1.3.4"},
      {: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"},
      {:plug_cowboy, "~> 1.0"}
    ]
  end

書き換えたらmix deps.getする。
色々と出るが、最後に以下が出てきたら成功

New:
  plug_cowboy 1.0.0
* Getting plug_cowboy (Hex package)

これでOK, mix phx.serverしよう!

僕もPhoneixは勉強し始めた所なので、もし良かったら一緒に勉強しましょう。
毎週火曜日の午前中にオンラインで勉強会してます。また、月に1回集まってやってます。

9
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Yoosuke
fukuokaex
エンジニア/企業向けにElixirプロダクト開発・SI案件開発を支援する福岡のコミュニティ

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
9
Help us understand the problem. What is going on with this article?