ueberauth / guardian

Elixir Authentication
MIT License
3.43k stars 379 forks source link

Fails to compile if optional plug dependency is missin #644

Closed aeons closed 4 years ago

aeons commented 4 years ago

I am not sure whether this is an issue for Guardian or for Elixir/mix, but here goes.

If you create an empty project and add {:guardian, "~> 2.0"} as a dependency, compilation fails with

𝝺 mix
==> jose
Compiling 105 files (.erl)
Compiling 8 files (.ex)
warning: Poison.EncodeError.exception/1 is undefined (module Poison.EncodeError is not available or is yet to be defined)
  lib/jose/poison/lexical_encoder.ex:8: JOSE.Poison.LexicalEncodeError.exception/1

Generated jose app
==> guardian
Compiling 24 files (.ex)

== Compilation error in file lib/guardian/plug/pipeline.ex ==
** (CompileError) lib/guardian/plug/pipeline.ex:109: module Plug.Conn is not loaded and could not be found
    (stdlib 3.11.1) lists.erl:1354: :lists.mapfoldl/3
    (stdlib 3.11.1) lists.erl:1355: :lists.mapfoldl/3
    (elixir 1.10.0) expanding macro: Kernel.if/2
could not compile dependency :guardian, "mix compile" failed. You can recompile this dependency with "mix deps.compile guardian", update it with "mix deps.update guardian" or clean it with "mix deps.clean guardian"

The referenced line is here https://github.com/ueberauth/guardian/blob/62744fb61fd62afe8bbb49b75b377be14aae65e6/lib/guardian/plug/pipeline.ex#L108-L110

doomspork commented 4 years ago

@aeons what version of Elixir are you on?

@ueberauth/developers have any of you seen this before? I don't think I've ever used Guardian without Plug. I can try to spin up an empty project to test.

aeons commented 4 years ago

Elixir 1.10.

I was trying to get sans_password updated to the newest guardian, and that does not have a dependency on anything except guardian.

Hanspagh commented 4 years ago

This is indeed a problem

== Compilation error in file lib/guardian/plug/pipeline.ex ==
** (CompileError) lib/guardian/plug/pipeline.ex:109: module Plug.Conn is not loaded and could not be found
    (stdlib) lists.erl:1354: :lists.mapfoldl/3
    (stdlib) lists.erl:1355: :lists.mapfoldl/3
    (elixir) expanding macro: Kernel.if/2

This part is wrapped in Code.ensure_loaded, but I guess it is a problem simular to this https://github.com/elixir-lang/elixir/issues/8970

Do we want to go that direction or should we just include plug as a dependency?

Hanspagh commented 4 years ago

@ueberauth/developers ?

wevnasc commented 4 years ago

I am having the same issue, I just added the plug as a dependency and solved, but I didn't want to add the plug without to use it, is there another way to solve it?

ramaboo commented 4 years ago

I am seeing this as well :(

Screen Shot 2020-08-06 at 18 12 11
Hanspagh commented 4 years ago

Fixed by #663