【问题标题】:Phoenix error: module not loaded/not available凤凰错误:模块未加载/不可用
【发布时间】:2015-12-21 16:53:07
【问题描述】:

我正在关注 Programming Phoenix 这本书,正在研究实现登录/注销经过身份验证的用户的部分,并且收到一个我不知道该怎么处理的错误:

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

我已经对照书检查并再次检查了我的代码,但什么也看不到。
我的项目文件在这里:https://github.com/bordeltabernacle/learning-phoenix/tree/master/rumbl

据我所知Rumbl.Auth.init 函数存在于auth.ex 控制器文件中,我不确定Rumbl.Router.Helpers 文件是什么或如何加载它。当我删除 router.ex 文件中唯一的新行时,由于应用程序正在运行,我得到了同样的错误。
恐怕我还不够了解,无法自己解决此问题。

【问题讨论】:

    标签: elixir phoenix-framework


    【解决方案1】:

    我认为你应该尝试清理deps,然后在up sever之前再次获取并编译

    所以试试

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

    祝你好运

    【讨论】:

    • mix deps.compile 帮助我不再检测到我的视图模块。
    • 在执行上述命令之前,还要删除 deps 中的所有文件夹,这可能会有所帮助
    【解决方案2】:

    https://github.com/bordeltabernacle/learning-phoenix/blob/master/rumbl/web/controllers/auth.ex 中有错字

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

    应该是

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

    【讨论】:

      【解决方案3】:

      您也可以删除_build 目录并使用mix phoenix.server (Phoenix 1.2) 或mix phx.server (Phoenix 1.3) 重新启动服务器。

      这样做将首次从头开始获取所有依赖项。我更喜欢这种方法,因为我不需要输入一堆命令,我只需要删除一个目录并在我的终端上重新运行最近的命令..这是mix phx.server。是的,我很懒。

      祝你好运。

      【讨论】:

        【解决方案4】:

        就我而言,发生此错误是因为我不小心在test 目录而不是lib 目录中创建了一个模块。将其移至 lib 目录修复它。

        【讨论】:

          【解决方案5】:

          在我的总括项目中,我在tests 目录中添加了一个新的support 目录,而我的测试无法访问其中的.ex 模块。

          默认情况下,mix 只在lib 目录中查找要编译的文件。您可以通过在mix.exs 中将elixirc_paths 添加到project 来添加另一个目录。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2016-04-08
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多