Ecto not starting or unavailable in local dependency project

I have a LiveView app (generated with the --no-ecto option) which depends on a local backend app. The backend app depends on Ecto. When I start the LiveView app, Ecto is apparently not starting:

LiveView app mix.exs:

  defp deps do
    [
      ...
      {:back_project, path: "../backend_project/"},
    ]
  end

Error upon running mix phx.server:

[error] #PID<0.686.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.685.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /
** (exit) an exception was raised:
    ** (RuntimeError) could not lookup Ecto repo BackendProject.Repo because it was not started or it does not exist

How do I force Ecto to start when I start the LiveView app?

I tried naming the dependency’s repo in the LiveView app’s application.ex, but this just gave me a cryptic error upon starting phx server:

erl_child_setup: failed with error 32 on line 281
[notice] Application liveview_app exited: shutdown

I added an entry to the LiveView app’s config, like

config :backend_project, ecto_repos: [BackendProject.Repo]
and repeated the full backend Repo configuration as it was presented in the backed config/config.exs app.

I did not supervise the backend repo from the LiveView app.

I guess this solution worked because the config in the dependency is ignored completely?

1 Like

I guess this solution worked because the config in the dependency is ignored completely?

Yeah that’s it! Here’s where it’s listed in the docs (from: Config — Elixir v1.15.6):

Also note that the config/config.exs of a library is not evaluated when the library is used as a dependency, as configuration is always meant to configure the current project. For more information, read our library guidelines.

1 Like