Plug fails to compile - (ArgumentError) invalid right argument for operator "in"

I’m trying to compile a elixir/phoenix app but I am getting the following error:

== Compilation error in file lib/plug/conn/utils.ex ==
** (ArgumentError) invalid right argument for operator "in", it expects a compile-time proper list or compile-time range on the right side when used in guard expressions, got: %{first: 65, last: 90, __struct__: Range, step: 1}
    (elixir 1.13.4) lib/kernel.ex:4245: Kernel.raise_on_invalid_args_in_2/1
    (elixir 1.13.4) expanding macro: Kernel.in/2
    lib/plug/conn/utils.ex:64: Plug.Conn.Utils.mt_first/2
could not compile dependency :plug, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile plug", update it with "mix deps.update plug" or clean it with "mix deps.clean plug"

I’ve tried cleaning my build, and repulling the deps.
I’m kinda out of ideas on how to get this working : |

I use elixir 1.13.4-otp-23 here is my deps:

defp deps do
    [
      {:phoenix, "~> 1.6.16"},
      {:phoenix_html, "~> 3.3.0"},
      {:telemetry_metrics, "~> 0.6.1"},
      {:telemetry_poller, "~> 1.0.0"},
      {:phoenix_live_view, "~> 0.17.6"},
      {:floki, ">= 0.30.0", only: :test},
      {:phoenix_live_dashboard, "~> 0.6.4"},

      {:plug, "~> 1.10"},
      {:phoenix_pubsub, "~> 2.0"},
      {:phoenix_ecto, "~> 4.4.0"},
      {:ecto, "~> 3.9.2", override: true},
      {:ecto_sql, "~> 3.9.2"},
      {:postgrex, "~> 0.14-rc", override: true},
      {:phoenix_live_reload, "~> 1.3"},
      {:gettext, "~> 0.19"},
      # {:cowboy, "~> 2.0"},
      {:plug_cowboy, "~> 2.0"},
      {:distillery, "~> 2.1", runtime: false},
      {:trailing_format_plug, "~> 0.0.5"},
      {:httpotion, "~> 3.0.2"},
      {:basic_auth, "~> 2.2.2"},
      {:jason, "~> 1.0"},
      {:timex, "~> 3.7.7"},
      {:poolboy, "~> 1.5.1"},
      {:logger_file_backend, "~> 0.0.10"},
      {:csv, "~> 2.4"},
      {:benchee, "~> 1.1"},
      {:flame_on, "~> 0.5.2"},
      {:ecto_psql_extras, "~> 0.6"}
    ]
  end

Plug does quite a lot of work at compile time (with some configuration options). This error suggests you have configured a plug with a runtime parameter when it needs a static compile time parameter. Are you able to show your router where you configure your plugs?

Here’s the part of the router with plugs, there are none other in the file:

pipeline :browser do
    plug(:accepts, ["html"])
    plug(:fetch_session)
    # plug(:fetch_flash)
    plug(:fetch_live_flash)
    plug(:protect_from_forgery)
    plug(:put_secure_browser_headers)
  end

  pipeline :api do
    plug(:accepts, ["json"])
  end

  pipeline :admin do
    plug(BasicAuth, use_config: {:myapp, :admin_config})
  end

  if Mix.env() == :dev do
    scope "/" do
      pipe_through :browser
      live_dashboard "/dashboard",
        ecto_repos: [MyApp.Repo],
        metrics: MyAppWeb.Telemetry,
        additional_pages: [
          flame_on: FlameOn.DashboardPage
        ]

    end
  end

Is this a new app or did you inherit it from someone? I’m guessing it’s older due to the versions.

Endpoint will also have a bunch of plus specified in it. Do you see the mt_first plug there?

I inherited this app, and I’m also starting out my elixir/phoenix journey as a junior dev.
I’ve had a bunch of experience in other environments and languages though.

Anyway, I looked at the endpoint file and didn’t find the mt_first plug anywhere.
A search in the whole project failed to find any references.

D’oh. It’s really hard to say, then. That file looks like it’s part of your project, maybe you could just try deleting it if it’s not used. Otherwise you may have to git bisect. Or maybe someone else here will notice something. Sorry I couldn’t be of more help.

I think I solved my problem.
I submitted an issue on the plug repo on github

Turns out I had conflicting installs of erlang, and it defaulted to the wrong one.
Once I made the switch everything was fine and dandy

1 Like

What did you do to fix it. How did you make the switch?

I use ASDF to control the languages versions on my POP!OS 22 computer.
I just used it to install the most recent version of erlang and elixir.
The caveat was erlang couldn’t install because of the base package openssl being outdated on my machine…
So I grabbed a compatible source release and updated it manually.
The asdf install worked then.