Phoenix release - Module not found

Hi
I have deployed a Phoenix app using Dockerfile, the Dockerfile is generated using mix mix phx.gen.release --docker
I have a module in prod/support/seeds.ex that is not compile for some reason in production, I am not able to call Utamktaba.Prod.Seeds.run because the module is not found.
The same module is available in the release if deployed using mix phx.gen.release
Did I miss something?

# mix.exs
def project do
    [
     # ...
      elixirc_paths: elixirc_paths(Mix.env()),
     # ...
    ]
  end

  defp elixirc_paths(:dev), do: ["lib", "dev/support"]
  defp elixirc_paths(:test), do: ["lib", "dev/support", "test/support"]
  defp elixirc_paths(_), do: ["lib", "prod/support"]

It does look like it should be there. Can you hop on a prod console and run Code.ensure_compiled(Utamktaba.Prod.Seeds) and then Code.ensure_loaded(Utamktaba.Prod.Seeds) and check what both return?

2 Likes

I got this error

nobody@c2bcaf2ac144:/app$ bin/utmaktaba remote
Erlang/OTP 24 [erts-12.2.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]

Interactive Elixir (1.13.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(utmaktaba@c2bcaf2ac144)1> Code.ensure_compiled(Utamktaba.Prod.Seeds)
{:error, :embedded}
iex(utmaktaba@c2bcaf2ac144)2> 

iex(utmaktaba@c2bcaf2ac144)1> Code.ensure_loaded(Utamktaba.Prod.Seeds)
{:error, :embedded}
iex(utmaktaba@c2bcaf2ac144)2> 

What’s the value of :build_embedded in your mix.exs?

There is no entry for :build_embedded

defmodule Utmaktaba.MixProject do
  use Mix.Project

  def project do
    [
      app: :utmaktaba,
      version: "0.4.0",
      elixir: "~> 1.12",
      elixirc_paths: elixirc_paths(Mix.env()),
      compilers: [:phoenix, :gettext] ++ Mix.compilers(),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps()
    ]
  end

  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [
      mod: {Utmaktaba.Application, []},
      extra_applications: [:logger, :runtime_tools]
    ]
  end

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:dev), do: ["lib", "dev/support"]
  defp elixirc_paths(:test), do: ["lib", "dev/support", "test/support"]
  defp elixirc_paths(_), do: ["lib", "prod/support"]

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
    [
      {:argon2_elixir, "~> 2.0"},
      {:phoenix, "~> 1.6.4"},
      {:phoenix_ecto, "~> 4.1"},
      {:ecto_sql, "~> 3.4"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_live_view, "~> 0.17.5"},
      {:floki, ">= 0.30.0", only: :test},
      {:phoenix_html, "~> 3.1"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:phoenix_live_dashboard, "~> 0.6"},
      {:telemetry_metrics, "~> 0.6.1"},
      {:telemetry_poller, "~> 1.0"},
      {:gettext, "~> 0.11"},
      {:jason, "~> 1.0"},
      {:plug_cowboy, "~> 2.5"},
      {:guardian, "~> 2.2"},
      {:mix_test_watch, "~> 1.1"},
      {:faker, "~> 0.17.0"},
      {:ex_machina, "~> 2.7"},
      {:timex, "~> 3.7"},
      {:esbuild, "~> 0.4", runtime: Mix.env() == :dev},
      {:swoosh, "~> 1.5"},
      {:xlsxir, "~> 1.6"},
      {:oban, "~> 2.10"}
    ]
  end

  # Aliases are shortcuts or tasks specific to the current project.
  # For example, to install project dependencies and perform other setup tasks, run:
  #
  #     $ mix setup
  #
  # See the documentation for `Mix` for more info on aliases.
  defp aliases do
    [
      setup: ["deps.get", "ecto.setup", "cmd npm install --prefix assets"],
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
      test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
      "assets.deploy": [
        "cmd --cd assets npm run deploy",
        "esbuild default --minify",
        "phx.digest"
      ]
    ]
  end
end

Ah, here is the explanation of your error: Erlang -- code

Basically: can’t use those functions in prod, more or less, because all modules are already loaded on startup.

So it’s back to square one.

The solution can be found here

https://github.com/phoenixframework/phoenix/issues/4697

1 Like