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?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
Have you recently upgraded Phoenix? Which version are you at now?
ericlathrop
Looks like I updated from Phoenix 1.5.8 → 1.5.10 on 8/12/2021. I’ll try reverting that.
ericlathrop
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
I’d try only using the
Routesmodule/alias first.ericlathrop
I spoke too soon. After re-deleting my
deps/_buildfolders, 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
Routesmodule/alias first”? I don’t understand.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.Helperstoalias HorseRacingNationWeb.Entries.Router.Helpers, as: Routesinlib/horse_racing_nation_web/entries.exEdit: 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
No, I grepped and we don’t have the word
Routesanywhere in our app. This is a fairly old app that’s been incrementally upgraded over time.ericlathrop
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
What happens if you comment out your entire
router.exand try to recompile?ericlathrop
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.