nerves-project / nerves

Craft and deploy bulletproof embedded software in Elixir
http://nerves-project.org
Apache License 2.0
2.23k stars 189 forks source link

Following the User Interfaces Tutorial for Phoenix Does Not Work #962

Closed panda2k closed 5 months ago

panda2k commented 5 months ago

Environment

Current behavior

When following the tutorial line by line, running mix deps.get in my_app_firmware results in the following error:

Dependencies have diverged:
* phoenix (Hex package)
  the :targets option for dependency phoenix

  > In /Users/michael/Programming/my_app/my_app_ui/mix.exs:
    {:phoenix, "~> 1.7.11", [targets: [:rpi, :rpi0, :rpi2, :rpi3, :rpi3a, :rpi4, :bbb, :osd32mp1, :x86_64, :grisp2, :mangopi_mq_pro], env: :prod, hex: "phoenix", repo: "hexpm"]}

  does not match the :targets option calculated for

  > In deps/phoenix_live_reload/mix.exs:
    {:phoenix, "~> 1.4", [only: :dev, targets: [:host], env: :prod, hex: "phoenix", repo: "hexpm", optional: false]}

  Ensure you specify at least the same targets in :targets in your dep
** (Mix) Can't continue due to errors on dependencies

This can be fixed by doing {:my_app_ui, path: "../my_app_ui", targets: [:host | @all_targets], env: Mix.env()}, in my_app_firmware/mix.exs (note [:host | @all_targets] instead of targets: @all_targets).

However, after doing this RingLogger.next reveals a new error when starting the server:

MyAppUi.Application.start(:normal, []) returned an error: shutdown: failed to start child: MyAppUiWeb.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([ref: MyAppUiWeb.Endpoint.HTTP, scheme: :http, plug: {MyAppUiWeb.Endpoint, []}, options: [port: 80, otp_app: :my_app_ui]])
            (phoenix 1.7.11) lib/phoenix/endpoint/cowboy2_adapter.ex:92: Phoenix.Endpoint.Cowboy2Adapter.child_spec/4
            (phoenix 1.7.11) lib/phoenix/endpoint/cowboy2_adapter.ex:66: anonymous fn/5 in Phoenix.Endpoint.Cowboy2Adapter.child_specs/2
            (elixir 1.16.1) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
            (phoenix 1.7.11) lib/phoenix/endpoint/cowboy2_adapter.ex:56: Phoenix.Endpoint.Cowboy2Adapter.child_specs/2
            (phoenix 1.7.11) lib/phoenix/endpoint/supervisor.ex:88: Phoenix.Endpoint.Supervisor.init/1
            (stdlib 5.2) supervisor.erl:330: :supervisor.init/1
            (stdlib 5.2) gen_server.erl:980: :gen_server.init_it/2

This error occurs because mix phx.new creates a project with bandit instead of plug_cowboy. To resolve this issue, people need to add adapter: Bandit.PhoenixAdapter to my_app_/my_app_firmware/config/target.exs

Expected behavior

The tutorial to work when following all the instructions

panda2k commented 5 months ago

Closed by #963