CompileError (invalid quoted expression) in EEX when deploying Phoenix 1.4 to Heroku

phoenix
eex
deployment
heroku

#1

I am having a trouble deploying my master branch to Heroku. When I deploy I get the following error:

    remote: == Compilation error in file lib/personal_inventory_web/views/layout_view.ex ==

    remote: ** (CompileError) lib/personal_inventory_web/templates/layout/_navigation.html.eex: invalid quoted expression: %{dynamic: [{:=, [], [{:arg0, [], Phoenix.HTML.Engine}, {:case, [generated: true], [{:link, [line: 27], ["Sign in with Google", [to: {{:., [line: 27], [{:__aliases__, [counter: 0, line: 27], [:Routes]}, :auth_path]}, [line: 27], [{{:., [line: 27], [{:__aliases__, [line: 27, alias: false], [:Phoenix, :HTML, :Engine]}, :fetch_assign!]}, [line: 27], [{:var!, [line: 27, context: Phoenix.HTML.Engine, import: Kernel], [{:assigns, [line: 27], Phoenix.HTML.Engine}]}, :conn]}, :request, "google", [scope: "email profile"]]}, class: "button"]]}, [do: [{:->, [generated: true], [[safe: {:data, [generated: true], Phoenix.HTML.Engine}], {:data, [generated: true], Phoenix.HTML.Engine}]}, {:->, [generated: true], [[{:when, [generated: true], [{:bin, [generated: true], Phoenix.HTML.Engine}, {:is_binary, [generated: true, context: Phoenix.HTML.Engine, import: Kernel], [{:bin, [generated: true], Phoenix.HTML.Engine}]}]}], {{:., [generated: true], [{:__aliases__, [generated: true, alias: false], [:Plug, :HTML]}, :html_escape_to_iodata]}, [generated: true], [{:bin, [generated: true], Phoenix.HTML.Engine}]}]}, {:->, [generated: true], [[{:other, [generated: true], Phoenix.HTML.Engine}], {{:., [line: 27], [{:__aliases__, [line: 27, alias: false], [:Phoenix, :HTML, :Safe]}, :to_iodata]}, [line: 27], [{:other, [line: 27], Phoenix.HTML.Engine}]}]}]]]}]}], iodata: [" </li>\n", {:arg0, [], Phoenix.HTML.Engine}, " <li class=\"nav-item\">\n"], vars_count: 1}

I was able to narrow it down to the following block of code, which I verified by removing it and witnessing successful deploy.

      <ul class="navbar-nav mr-auto">
        <%= if @conn.assigns[:user] do %>
          <li class="nav-item">
            Logged in as <%= @conn.assigns.user.first_name %>
          </li>
          <li class="nav-item">
            <%= link "Sign out", to: Routes.auth_path(@conn, :delete), class: "button alert" %>
          </li>
        <% else %>
          <li class="nav-item">
            <%= link "Sign in with Google", to: Routes.auth_path(@conn, :request, "google", scope: "email profile"), class: "button" %>
          </li>
        <% end %>
      </ul>

I really can’t see which part of quoted expression could be a problem here. I searched on the web, but didn’t really find anyone else having the similar issue. I hope it’s something very simple I am just overlooking. Locally, it works without any problems.

Thank you so much in advance!


#2

What is your Elixir version on Heroku? It is likely that Phoenix is using more recent features of Elixir (to be more precise, of Elixir v1.5.1+) and you are on an earlier version.


#3

Yup, you were right. I am using Elixir v1.7, but heroku was using v1.5. I didn’t have elixir_buildpack.config configured and saved in my root directory. Specifying correct version on that fixed the issue.

Thank you!


#4

I’m seeing the same issue trying to deploy a pretty basic Phoenix app to heroku.

I’ve tried to follow what was recommended:

  • I’ve created a elixir_buildpack.config file with elixir_version=1.5.0 inside
    (I’m targetting 1.5.0 since Heroku’s logs show its using this version of Elixir)
  • I’ve also updated mix.exs's project function to have elixir: "1.5.0".

Worth nothing that if I remove the piece of code in my template, the app correctly builds but I’m getting other errors, such as when I try to migrate the database with heroku run mix ecto.migrate.

My template code is as follow:

<%= for original <- Enum.shuffle(all_originals) do %>
      <div class="originals__original">
        <%= raw(original.svg) %>
        <p>
          <span><%= original.name %></span>
        </p>
      </div>
    <% end %>

all_originals is a view helper that queries all my models from the db and returns them.

Then error I’m getting when trying to migrate the database is

$ heroku run mix ecto.migrate
Running mix ecto.migrate on ⬢ fathomless-wave-60767... up, run.3483 (Free)
** (EXIT from #PID<0.74.0>) an exception was raised:
    ** (ArgumentError) supervisors expect the child to be a module, a {module, arg} tuple or a map with the child specification, got: {DBConnection.ConnectionPool, {Ecto.Repo.Supervisor, :start_child, [{DBConnection.ConnectionPool, :start_link, [{Postgrex.Protocol, [types: Postgrex.DefaultTypes, hostname: "localhost", port: 5432, repo: Avatar.Repo, telemetry_prefix: [:avatar, :repo], otp_app: :avatar, timeout: 15000, pool_size: 2, pool: DBConnection.ConnectionPool]}]}, Ecto.Adapters.Postgres, #Reference<0.3877715190.1770389505.102806>, %{opts: [timeout: 15000, pool_size: 2, pool: DBConnection.ConnectionPool], sql: Ecto.Adapters.Postgres.Connection, telemetry: {:debug, [], [:avatar, :repo, :query]}}]}, :permanent, 5000, :worker, [DBConnection.ConnectionPool]}
        (elixir) lib/supervisor.ex:609: Supervisor.init_child/1
        (elixir) lib/enum.ex:1255: Enum."-map/2-lists^map/1-0-"/2
        (elixir) lib/supervisor.ex:581: Supervisor.init/2
        (stdlib) supervisor.erl:294: :supervisor.init/1
        (stdlib) gen_server.erl:365: :gen_server.init_it/2
        (stdlib) gen_server.erl:333: :gen_server.init_it/6
        (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3

Please note that everything works great on local.


#5

What version of ecto and db_connection are you using? Please tell us the versions specified in your mix.exs and the version effectively locked via mix.lock.


#6

Sorry I just fixed this actually :slight_smile:

Looking at Heroku logs I noticed that it was building Elixir v 1.5.0 so I forced this everywhere. A better understanding of buildpacks and Phoenix configs, I actually went and bumped Elixir version to 1.6.5 everywhere (that’s what is running on my local machine) and now the build on heroku with the template code is working!

I’ve also been able to migrate the database now!