If you're using Dependabot to manage dependencies in your Phoenix application, you might have encountered this error:
** (ArgumentError) The module Phoenix.CodeReloader was given as a
child to a supervisor but it does not exist
Why This Happens
Phoenix.CodeReloader
is a development-time module that watches your code for changes and reloads it automatically. However, Dependabot doesn't actually need (or have access to) this module when it's checking for dependency updates. When Dependabot tries to load your application to verify dependencies, it fails because it's attempting to start a supervisor with a module that isn't available in its minimal environment.
The Solution
The fix is straightforward: conditionally exclude Phoenix.CodeReloader
when running in Dependabot's environment. Dependabot sets the DEPENDABOT_HOME
environment variable, which we can use to detect when our code is running in that context.
Add a listeners/0
function to your mix.exs
:
def project() do
[
app: :my_app,
version: "0.1.0",
elixir: "~> 1.18",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps(),
listeners: listeners(),
consolidate_protocols: Mix.env() != :dev
]
end
defp listeners() do
if System.get_env("DEPENDABOT_HOME") do
[]
else
[Phoenix.CodeReloader]
end
end