Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

module Myapp.Router.Helpers is not loaded and could not be found

A compilation error in an Elixir/Phoenix application:

== Compilation error on file web/views/layout_view.ex ==
** (CompileError) web/views/layout_view.ex:2: module Myapp.Router.Helpers is not loaded and could not be found
    expanding macro: Myapp.Web.__using__/1
    web/views/layout_view.ex:2: Myapp.LayoutView (module)
    (elixir) expanding macro: Kernel.use/2
    web/views/layout_view.ex:2: Myapp.LayoutView (module)
    (elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1

My web.ex is a standard one, nothing new in it.

like image 458
Jio Avatar asked Nov 12 '16 08:11

Jio


1 Answers

I've seen this happening if one of the plugs imports MyApp.Router.Helpers, and is used in the MyApp.Router itself at the same time. This creates a compiler deadlock - in order to compile the router the plug is required, but in order to compile the plug, the router (and helper module) is required.

You can fix this by using fully qualified calls to the router helpers instead of importing them, i.e.

alias MyApp.Router.Helpers, as: Routes
Routes.foo_path(conn, :create)
like image 91
michalmuskala Avatar answered Oct 26 '22 07:10

michalmuskala