My tests started randomly failing in GitLab one day. I say randomly because re-running the tests for previously passing code, now has them failing. I was able to reproduce on my laptop by deleting all my
_build folders, deleting all my docker volumes/images/etc, and rebuilding everything from blank.
I’m getting this compilation error:
== Compilation error in file lib/horse_racing_nation_web/entries/views/picks_view.ex == ** (CompileError) lib/horse_racing_nation_web/entries/views/picks_view.ex:2: module HorseRacingNationWeb.Entries.Router.Helpers is not loaded and could not be found expanding macro: HorseRacingNationWeb.Entries.__using__/1 lib/horse_racing_nation_web/entries/views/picks_view.ex:2: HorseRacingNationWeb.Entries.PicksView (module) (elixir 1.11.4) expanding macro: Kernel.use/2 lib/horse_racing_nation_web/entries/views/picks_view.ex:2: HorseRacingNationWeb.Entries.PicksView (module)
The view file in the error:
defmodule HorseRacingNationWeb.Entries.PicksView do use HorseRacingNationWeb.Entries, :view <snip> end
I think this file is pretty much what Phoenix generates.
defmodule HorseRacingNationWeb.Entries do def controller do quote do use Phoenix.Controller, namespace: HorseRacingNationWeb.Entries import Plug.Conn import HorseRacingNationWeb.Entries.Router.Helpers import HorseRacingNationWeb.Gettext end end def view do quote do use Phoenix.View, root: "lib/horse_racing_nation_web/entries/templates", namespace: HorseRacingNationWeb.Entries # Import convenience functions from controllers import Phoenix.Controller, only: [get_flash: 2, view_module: 1] # Use all HTML functionality (forms, tags, etc) use Phoenix.HTML import HorseRacingNationWeb.Entries.Router.Helpers import HorseRacingNationWeb.Entries.ErrorHelpers import HorseRacingNationWeb.Gettext end end def router do quote do use Phoenix.Router import Plug.Conn import Phoenix.Controller end end def channel do quote do use Phoenix.Channel import HorseRacingNationWeb.Gettext end end @doc """ When used, dispatch to the appropriate controller/view/etc. """ defmacro __using__(which) when is_atom(which) do apply(__MODULE__, which, ) end end
defmodule HorseRacingNationWeb.Entries.Router do use HorseRacingNationWeb.Entries, :router use Honeybadger.Plug pipeline :browser do plug(:accepts, ["html"]) <snip> end pipeline :api do plug(:accepts, ["json"]) <snip> end scope "/api", HorseRacingNationWeb.Entries, as: "api" do pipe_through(:api) <snip> end scope "/", HorseRacingNationWeb.Entries do pipe_through(:browser) <snip> end end
I thought maybe there was some sort of circular dependency because both
HorseRacingNationWeb.Entries.Router are using
HorseRacingNationWeb.Entries, so I tried to inline the
use in the router. That didn’t help.
The code all seems to be correct to me, and I’ve been banging my head against a wall for too long. I’m guessing the router helpers aren’t being generated, but I don’t know why. Can someone help?