bordeltabernacle
bordeltabernacle

Reputation: 1653

Phoenix error: module not loaded/not available

I'm following the Programming Phoenix book, working on the section to implement logging in/out an authenticated user, and am receiving an error I don't know what to do with:

mix phoenix.server
Compiled lib/rumbl.ex
Compiled lib/rumbl/repo.ex
Compiled web/channels/user_socket.ex
Compiled web/web.ex
Compiled web/models/user.ex

== Compilation error on file web/router.ex ==
** (UndefinedFunctionError) undefined function: Rumbl.Auth.init/1 (module Rumbl.Auth is not available)
    Rumbl.Auth.init([repo: Rumbl.Repo])
    (plug) lib/plug/builder.ex:198: Plug.Builder.init_module_plug/3
    (plug) lib/plug/builder.ex:186: anonymous fn/4 in Plug.Builder.compile/3
    (elixir) lib/enum.ex:1387: Enum."-reduce/3-lists^foldl/2-0-"/3
    (plug) lib/plug/builder.ex:186: Plug.Builder.compile/3
    web/router.ex:4: (module)
    (stdlib) erl_eval.erl:669: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:100: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/8


== Compilation error on file lib/rumbl/endpoint.ex ==
** (UndefinedFunctionError) undefined function: Rumbl.Router.init/1 (module Rumbl.Router is not available)
    Rumbl.Router.init([])
    (plug) lib/plug/builder.ex:198: Plug.Builder.init_module_plug/3
    (plug) lib/plug/builder.ex:186: anonymous fn/4 in Plug.Builder.compile/3
    (elixir) lib/enum.ex:1387: Enum."-reduce/3-lists^foldl/2-0-"/3
    (plug) lib/plug/builder.ex:186: Plug.Builder.compile/3
    (phoenix) expanding macro: Phoenix.Endpoint.__before_compile__/1
    lib/rumbl/endpoint.ex:1: Rumbl.Endpoint (module)
    (elixir) lib/kernel/parallel_compiler.ex:100: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/8


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


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


== Compilation error on file web/controllers/auth.ex ==
** (CompileError) web/controllers/auth.ex:3: module Comeonin.Bcypt is not loaded and could not be found
    (stdlib) erl_eval.erl:669: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:100: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/8


== Compilation error on file web/controllers/user_controller.ex ==
** (CompileError) web/controllers/user_controller.ex:2: module Rumbl.Router.Helpers is not loaded and could not be found
    expanding macro: Rumbl.Web.__using__/1
    web/controllers/user_controller.ex:2: Rumbl.UserController (module)
    (elixir) expanding macro: Kernel.use/2
    web/controllers/user_controller.ex:2: Rumbl.UserController (module)
    (elixir) lib/kernel/parallel_compiler.ex:100: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/8


== Compilation error on file web/controllers/page_controller.ex ==
** (CompileError) web/controllers/page_controller.ex:2: module Rumbl.Router.Helpers is not loaded and could not be found
    expanding macro: Rumbl.Web.__using__/1
    web/controllers/page_controller.ex:2: Rumbl.PageController (module)
    (elixir) expanding macro: Kernel.use/2
    web/controllers/page_controller.ex:2: Rumbl.PageController (module)
    (elixir) lib/kernel/parallel_compiler.ex:100: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/8


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


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


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


== Compilation error on file web/controllers/session_controller.ex ==
** (CompileError) web/controllers/session_controller.ex:2: module Rumbl.Router.Helpers is not loaded and could not be found
    expanding macro: Rumbl.Web.__using__/1
    web/controllers/session_controller.ex:2: Rumbl.SessionController (module)
    (elixir) expanding macro: Kernel.use/2
    web/controllers/session_controller.ex:2: Rumbl.SessionController (module)
    (elixir) lib/kernel/parallel_compiler.ex:100: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/8

I've checked and double checked my code against the book, but can't see anything.
My files for the project are here: https://github.com/bordeltabernacle/learning-phoenix/tree/master/rumbl

As far as I can tell the Rumbl.Auth.init function is there in the auth.ex controller file, and I'm not sure what the Rumbl.Router.Helpers file is or how to load it. When i remove the only new line in the router.ex file, since the app was working, I get the same error.
I'm afraid I don't yet know enough to troubleshoot this myself.

Upvotes: 18

Views: 17253

Answers (5)

Erion S
Erion S

Reputation: 1633

In my umbrella project, I added a new support directory within the tests directory and the .ex modules within were not accessible to my tests.

By default, mix looks only within the lib directory for files to compile. You can add another directory by adding elixirc_paths to project in your mix.exs.

Upvotes: 0

Zoltán
Zoltán

Reputation: 22146

In my case this error happened because I accidentally created a module in the test directory instead of the lib directory. Moving it to the lib directory fixed it.

Upvotes: 0

dsignr
dsignr

Reputation: 2354

You could also delete the _build directory and restart your server with mix phoenix.server (Phoenix 1.2) or mix phx.server (Phoenix 1.3).

Doing this will fetch all dependencies from scratch for the first time. I prefer this method as I don't need to type a bunch of commands, I just need to delete a directory and re-run the recent command on my terminal..which is mix phx.server. Yeah, I'm lazy.

Good luck.

Upvotes: 1

Dmytro Biletskyi
Dmytro Biletskyi

Reputation: 1903

You've got typo in https://github.com/bordeltabernacle/learning-phoenix/blob/master/rumbl/web/controllers/auth.ex

import Comeonin.Bcypt, only: [checkpw: 2]

should be

import Comeonin.Bcrypt, only: [checkpw: 2]

Upvotes: 10

Lê Minh Duy
Lê Minh Duy

Reputation: 249

I think you should try to clean up deps, then get and compile again before up sever

so try

mix deps.clean --all
mix deps.get
mix deps.compile
mix phoenix.server

Good luck

Upvotes: 24

Related Questions