Compilation error on file web/controllers/auth_controller.ex undefined function plug/1

863 Views Asked by At

The Cryptic Error Message

While attempting to implement ueberauth for our project, we cam across a error message we had not seen before. (note this is not specific to ueberauth this error will be seen in any controller that fails to include the controller "helpers")

The exact error message is:

== Compilation error on file web/controllers/auth_controller.ex ==
** (CompileError) web/controllers/auth_controller.ex:4: undefined function plug/1
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1

Code Snapshot: https://github.com/dwyl/auth/pull/9/commits/e2550c558832ff9c4a442b570224a1ccacbfdb02

Answer:

Forgot to include :controller helpers in our controller file ...

use Auth.Web, :controller

Thanks to Sam Houston for taking a look at the code and spotting how to fix it. https://github.com/dwyl/auth/pull/9/commits/823f7d79561f733a9d131b26a3f6a4d74da59842

Posting this question + answer in case someone else sees this error message in their Phoenix project and does not find an answer when googling.

2

There are 2 best solutions below

0
On

The plug macro is defined in Plug.Builder and you could import it before usage with:

use Plug.Builder

plug :any_plug_you_like

in case of Phoenix it defined in Phoenix.Controller.Pipeline which injected in Phoenix.Controller which again injected via use Auth.Web, :controller.

0
On

Sharing the answer for others to interpret it.

use Auth.Web, :controller