Solved: Fresh install: `mix test` produces `could not call Module.put_attribute/3 because the module Fragments.MixProject is already compiled`

I am using Elixir on a M2 Mac running the latest Sonoma. I last used Elixir on an M1 Mac running who knows what.

Short version: I can’t make the Homebrew version work. The asdf version won’t build Erlang.


Homebrew

When I do mix new fragments, mix test produces this:

== Compilation error in file lib/fragments.ex ==
** (ArgumentError) could not call Module.put_attribute/3 because the module Fragments.MixProject is already compiled
    (elixir 1.16.0) lib/module.ex:2360: Module.assert_not_readonly!/2
    (elixir 1.16.0) lib/module.ex:2041: Module.__put_attribute__/5
    lib/fragments.ex:2: (module)

This happens even after the following:

brew update
brew upgrade
brew uninstall elixir erlang
brew uninstall --force erlang
brew install elixir
rm -rf fragments
mix new fragments

ASDF version

I then followed these Stackoverflow instructions. However, when I did asdf install erlang latest, I got this in the log:

checking for OpenSSL header in /usr/local/opt/openssl@1.1... yes
checking for OpenSSL in /usr/local/opt/openssl@1.1... configure: error: neither static nor dynamic crypto library found in /usr/local/opt/openssl@1.1
ERROR: /Users/bem/.asdf/plugins/erlang/kerl-home/builds/asdf_26.2.1/otp_src_26.2.1/lib/crypto/configure failed!

I had previously done a brew install openssl to get openssl version 3.2.0_1, which I understand was an appropriate version for Erlang 26.

Note, as far as I can tell, there are no stray versions of Erlang or Elixir lying around on the machine:

bem@ebenezer2023 fragments % which erl
/usr/local/bin/erl
bem@ebenezer2023 fragments % ls -l /usr/local/bin/erl
lrwxr-xr-x  1 bem  admin  31 Jan  1 15:29 /usr/local/bin/erl -> ../Cellar/erlang/26.2.1/bin/erl
bem@ebenezer2023 fragments % which elixir
/usr/local/bin/elixir
bem@ebenezer2023 fragments % ls -l /usr/local/bin/elixir
lrwxr-xr-x  1 bem  admin  34 Jan  1 15:29 /usr/local/bin/elixir -> ../Cellar/elixir/1.16.0/bin/elixir

Figured it out. It turns out that brew update is not sufficient when you have migrated from an Intel mac to an Apple Silicon one. You need to install from scratch. On Apple Silicon apps, brew manages the opt/homebrew directory rather than the old /usr/local. My suspicion is that the old configuration was compiling for Intel and relying on Rosetta to do translation, which doesn’t work.

3 Likes