Dependabot and Phoenix 1.8.x's CodeReloader Don't Work Together

Unless you do this trick.

Dependabot and Phoenix 1.8.x's CodeReloader Don't Work Together
Photo by Thomas Stephan / Unsplash

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

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to George Guimarães..

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.