Skip to content

Changing compile-time config of a Hex dependency leaves it stale and permanently fails compile-env validation #15467

Description

@zachdaniel

Existing issue

  • I have searched existing issues and could not find a duplicate.

Elixir and Erlang/OTP versions

Erlang/OTP 29 [erts-17.0] [source] [64-bit] [smp:14:14] [ds:14:14:10] [async-threads:1] [jit]

Operating system

MacOS

Current behavior

When a fetchable (Hex) dependency reads app config via Application.compile_env/3, and
that key is added or changed in the parent project's config/config.exs after the
dependency was compiled, mix compile fails — and keeps failing on every subsequent
run until the dep is manually rebuilt with mix deps.compile <dep> --force or mix deps.clean <dep> --build.

Reproduction

mix new repro
cd repro
mkdir config
echo 'import Config' > config/config.exs
echo 'defmodule Repro.MixProject do use Mix.Project; def project do [app: :repro,
version: "0.1.0", elixir: "~> 1.17", deps: [{:plug, "1.18.1"}]] end; def application do
[extra_applications: [:logger]] end end' > mix.exs
mix deps.get
mix compile
echo 'config :plug, :statuses, %{418 => "Totally A Teapot"}' >> config/config.exs
mix compile

Output

could not compile dependency :plug, "mix compile" failed. Errors may have been logged
above. ...
** (Mix) the application :plug has a different value set for key :statuses during
runtime compared to compile time. ...
  * Compile time value was not set
  * Runtime value was set to: %{418 => "Totally A Teapot"}

This breaks real-world installer flows: mix igniter.install ash ... writes
compile-time config entries for already-compiled Hex deps and then runs further mix
tasks, which now fail permanently. Originally reported at
ash-project/ash#2750.

Analysis

I got this from claude, I have not verified it, but I'm leaving it here inc are it helps. I was able to confirm that 1.20.0-rc.4 does not have this issue, so it sounds like it may be on the right track at least 😄


The regression was introduced by fb2657a ("Fix compile env change triggering full
recompilation of path dependencies", #15188), first released in 1.20.0-rc.5.

Before that commit, a diverged compile env gave the dep status :compile
(Mix.Dep.Loader.compile_env_status/2), which was compilable?, so
Mix.Tasks.Deps.Compile.compile_single/3 removed the dep's build dir and a clean
rebuild picked up the new env.

Expected behavior

Successful compile with the reproduction above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions