ericlathrop

ericlathrop

Need help figuring out compilation error involving Router Helpers

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?

Most Liked Switch mode

dimitarvp

dimitarvp

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

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

dimitarvp

dimitarvp

There was a migration required a while ago when upgrading (from Phoenix 1.3 to 1.4 I believe but I might be wrong) that did away with having import-ed path/url functions. You had to use Routes.xxxx_path from then on.

Last Post!

ericlathrop

ericlathrop

Correct. I finished making all those changes, and now it’s exploding with this:

== Compilation error in file lib/horse_racing_nation_web/amp/router.ex ==
** (CompileError) lib/horse_racing_nation_web/amp/router.ex:3: module Honeybadger.Plug is not loaded and could not be found
    (elixir 1.11.4) expanding macro: Kernel.use/1
    lib/horse_racing_nation_web/amp/router.ex:3: HorseRacingNationWeb.Amp.Router (module)

But the honeybadger hex package is definitely installed and there:

mix.lock:

  "honeybadger": {:hex, :honeybadger, "0.17.0", "4c6682bfe17907788d1d61338f123e2d698e15354c3868372e392c3dc2f729aa", [:mix], [{:ecto, ">= 2.0.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:hackney, "~> 1.1", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.0.0 and < 2.0.0", [hex: :phoenix, repo: "hexpm", optional: true]}, {:plug, ">= 1.0.0 and < 2.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a97182bbf7b09de3112393ee080f133637d9fdb1535765548e89b69977c43621"},

I can comment out the use Honeybadger.Plug, and everything finally works, but obviously I’d prefer that my error reporting is still enabled.

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
saveman71
Hello ! We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement