Elixir "(Mix) Could not start application" in CI
Mix tried to start an OTP application and its start callback or a child in its supervision tree crashed during boot, so the app never came up.
What this error means
The task aborts with (Mix) Could not start application X: ... (EXIT) ... or a :bad_return from the start callback, naming the failing app. It is usually deterministic, though missing-service boots can be transient.
** (Mix) Could not start application my_app:
MyApp.Application.start(:normal, []) returned an error:
shutdown: failed to start child: MyApp.Repo
** (EXIT) :econnrefusedCommon causes
A child process crashes on init
A supervised child (Repo, a GenServer) fails in init - often a config it needs is missing or a service it connects to is unreachable.
Invalid runtime configuration
config/runtime.exs reads an env var that is unset in CI, so the start callback returns an error.
Dependent service unavailable
The app needs a database or cache that is not started yet, so the connecting child cannot boot.
How to fix it
Provide the required config and services
Set the env vars the app reads at boot and start dependent services first.
# CI step
export DATABASE_URL="ecto://postgres:postgres@localhost/my_app_test"
mix ecto.create && mix testMake boot resilient
- Confirm each supervised child can start in the CI env.
- Add readiness checks before the app starts dependent children.
- Validate runtime config and fail with a clear message.
Re-run transient boot failures
When a child cannot reach a service that is still starting, the boot is transient. Latchkey managed runners self-heal transient boot/connection failures by auto-retrying so a one-off race does not fail the job.
How to prevent it
- Start dependent services before the app in CI.
- Validate runtime config explicitly at boot.
- Add readiness gates for external dependencies.