ericlathrop

ericlathrop

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 deps and _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:

lib/horse_racing_nation_web/entries/views/picks_view.ex

defmodule HorseRacingNationWeb.Entries.PicksView do
  use HorseRacingNationWeb.Entries, :view

  <snip>
end

I think this file is pretty much what Phoenix generates.

lib/horse_racing_nation_web/entries.ex

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

My router.
lib/horse_racing_nation_web/entries/router.ex

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.PicksView and 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?

Showing Posts 1 to 10

dimitarvp

dimitarvp

Have you recently upgraded Phoenix? Which version are you at now?

ericlathrop

ericlathrop OP

Looks like I updated from Phoenix 1.5.8 → 1.5.10 on 8/12/2021. I’ll try reverting that.

ericlathrop

ericlathrop OP

Reverting to phoenix 1.5.8 fixed it! Thanks for getting me unstuck!

I don’t see anything in the Phoenix changelog that makes it look like that was supposed to break, so I’ll file an issue.

dimitarvp

dimitarvp

I’d try only using the Routes module/alias first.

ericlathrop

ericlathrop OP

I spoke too soon. After re-deleting my deps/_build folders, deleting all my docker volumes/images/etc, I still have the same compile error on Phoenix 1.5.8.

What do you mean “only using the Routes module/alias first”? I don’t understand.

joddm

joddm

Could it be that you are using routes helper functions like Routes. in your view/template?

If so try changing import HorseRacingNationWeb.Entries.Router.Helpers to alias HorseRacingNationWeb.Entries.Router.Helpers, as: Routes in lib/horse_racing_nation_web/entries.ex

Edit: Also check out Module BpmServer.Router.Helpers is not loaded and could not be found - #3 by benwilson512

But I think that would also be resolved by aliasing as mentioned above

ericlathrop

ericlathrop OP

No, I grepped and we don’t have the word Routes anywhere in our app. This is a fairly old app that’s been incrementally upgraded over time.

ericlathrop

ericlathrop OP

I checked all my plugs, and none of them refer to the Router or Router.Helpers. I also tried commenting out all my custom plugs in my router, and that didn’t help anything.

joddm

joddm

What happens if you comment out your entire router.ex and try to recompile?

ericlathrop

ericlathrop OP

I’ll try that next. Currently I changed all the “import Router.Helpers” to “alias Router.Helpers, as: Routes” and I’m working on fixing 1,000 compile errors.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews