Configuration of dependency is followed with error (yet it seems to work) on startup

Hi, I’m having troubles find out why the following error occures during startup:

You have configured application :ecto_gen in your configuration file,
but the application is not available.

This usually means one of:

  1. You have not added the application as a dependency in a mix.exs file.

  2. You are configuring an application that does not really exist.

Please ensure :ecto_gen exists or remove the configuration.

Background: I have a phoenix project and I have added dependecy ecto_gen (that I created) and it expects a configuration entry in config/config.exs:

config :ecto_gen, # <---
  otp_app: :my_app
  db_config: MyRepo,
  output_location: "apps/database_generated"
  # ...etc
  ]

and it is listed as dependency:

  defp deps do
    [
      {:ecto_gen, "~> 0.8", runtime: false}, # <---
      {:gelfx, "~> 1.0"},
      {:jason, "~> 1.0"}
    ]
  end

It seems the setup I have does work e.g. the config values are read correctly when I run mix task of the ecto_gen dependency but the error on each start of recompiled app scares me quite often… :slight_smile:

Thanks

What happens if You remove runtime: false?

Same… error persists.

A common reason for an error like this is using the :applications key instead of :extra_applications in the application/0 function of your mix.exs. Perhaps that is the problem? If not maybe showing your whole mix.exs would be helpful.

1 Like

Use config/dev.exs instead.

1 Like

This is my mix.exs

defmodule MyApp.Umbrella.MixProject do
  use Mix.Project

  def project do
    [
      apps_path: "apps",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      version: {:from_app, :my_app},
      releases: [
        my_app: [
          applications: [
            my_app: :permanent,
            my_app_web: :permanent,
            my_app_administration_web: :permanent
          ]
        ]
      ]
    ]
  end

  defp deps do
    [
      {:ecto_gen, "~> 0.8", runtime: false},
      {:gelfx, "~> 1.0"},
      {:jason, "~> 1.0"}
    ]
  end
end

But I wish to have this configuration shared across all environments. Is there a better place for such configuration?

If you are interested, here is reproducible repo:

After setup (deps.get deps.compile) you can start this with iex -S mix and at the end of project compilation the before-mentioned error should arise.

It already has the db code generated so you should not need to have a running postgres database

Thanks for the reproducible project! The problem is that you need to add the :ecto_gen dependency to one of your applications in the umbrella, either :ecto_gen_error_reproduce or :ecto_gen_error_reproduce_web (or both). You should basically never add dependencies to the root mix.exs. Although I’m having some trouble finding where that is documented (I would’ve expected it to appear in Dependencies and umbrella projects - The Elixir programming language).

Yes, in that case you should use config/config.exs for the configuration.

3 Likes

I see. That is intersting to hear…
In the beggining I was afraid that by moving to the nested app the mix task provided by ecto_gen package would be unaccessible from project root but thats not the case…
And it indeed removes the error.

Thank you!

1 Like