chris-wickens

chris-wickens

Unable to compile default Elixir project from the getting started guide

New to Elixir, I’m trying to compile the default project in the getting started guide and get this error:

mix compile
Compiling 1 file (.ex)

== Compilation error in file lib/kv.ex ==
** (ArgumentError) could not call Module.put_attribute/3 because the module KV.MixProject is already compiled
    (elixir 1.15.4) lib/module.ex:2310: Module.assert_not_readonly!/2
    (elixir 1.15.4) lib/module.ex:2007: Module.__put_attribute__/5
    lib/kv.ex:2: (module)

I encountered an OpenSSL problem I wasn’t able to workaround while installing erlang via asdf on my M1 mac. Eventually had to install erlang through homebrew which I gather is not recommended, so perhaps that may be part of the problem.

elixir 1.15.4-otp-26
erlang 26.0.2

Marked As Solved

chris-wickens

chris-wickens

After uncountable attempts I found that reinstalling the asdf erlang plugin allowed me to then install erlang via asdf without the crypto library error, and now mix compile is building the default project as intended. :tada:

I did install the erlang plugin slightly differently with asdf plugin add erlang instead of asdf plugin add erlang https://github.com/asdf-vm/asdf-erlang.git, don’t see why that would make a difference but I thought I’d note it.

Along the way I also reinstalled homebrew but I don’t know whether that made a difference, it didn’t help until after I reinstalled the erlang asdf plugin at least. In the end I only had openssl@3 installed and no flags or options were set in .zshrc.

Thanks everybody for your help!

Also Liked

Raf

Raf

NOTE: Found a solution to the problem I was having. See edit2 note below.

I’ve been struggling with this issue for a few hours now. I’m on macOS and the project runs just fine on my machine, but to deploy (to AWS), I need to build a docker image passing --platform=linux/amd64, e.g.:

ARG ELIXIR_VERSION=1.17.2
ARG OTP_VERSION=27.0.1
ARG NODE_VERSION=20.x
ARG DEBIAN_VERSION=bullseye-20240701-slim

ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"

# ---- stage: builder
FROM --platform=linux/amd64 ${BUILDER_IMAGE} AS builder

The Elixir version I have there is quite new, but I had it set to 1.16 before and it presented the same issue. When I try to build, this is the error I get:

 => [builder  8/18] COPY mix.exs mix.lock ./                                                                                             0.0s
 => [builder  9/18] RUN mix deps.get --only prod                                                                                         3.9s
 => ERROR [builder 10/18] RUN mix deps.compile                                                                                           1.7s
------
 > [builder 10/18] RUN mix deps.compile:
1.165 ==> decimal
1.165 Compiling 4 files (.ex)
1.669 Generated decimal app
1.675 ==> my_app_name
1.676 Error while loading project :mime at /app/deps/mime
1.678 ** (ArgumentError) could not call Module.put_attribute/3 because the module MyAppName.MixProject is already compiled
1.678     (elixir 1.17.2) lib/module.ex:2365: Module.assert_not_readonly!/2
1.678     (elixir 1.17.2) lib/module.ex:2046: Module.__put_attribute__/5
1.678     /app/deps/mime/mix.exs:2: (module)
------
Dockerfile:59
--------------------
  57 |     COPY mix.exs mix.lock ./
  58 |     RUN mix deps.get --only $MIX_ENV
  59 | >>> RUN mix deps.compile
  60 |
  61 |     COPY assets assets
--------------------
ERROR: failed to solve: process "/bin/sh -c mix deps.compile" did not complete successfully: exit code: 1

The image builds just fine if I don’t pass the --platform, so if I have:

FROM ${BUILDER_IMAGE} AS builder

Then the image builds and runs fine on my machine, but then I can’t use in in AWS - at least with what I have access (all other services are built for amd64 to work on our infra.

Any help at this point would be much appreciated!

edit: Just found this other related question here: Cross-platform specific error when installing latest hex (unfortunately, without a solution - I’ll keep looking).

edit2: Finally found a solution to the problem in this other question: Elixir docker image won't build for linux/arm64/v8 using Github Actions - #13 by yuriploc

It suggests adding ERL_FLAGS="+JPperf true" to the environment and so I did in my Dockerfile, so now I have:

FROM --platform=linux/amd64 ${BUILDER_IMAGE} AS builder
...
# set build ENV
ENV MIX_ENV="prod"
ENV ERL_FLAGS="+JPperf true"

# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config

# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile
tt67wq

tt67wq

I also encountered this problem, and later I realized that the data on my Mac was migrated from the Intel version to the Apple version, so underlying libraries like OpenSSL were adapted for x86, so when I compiled Erlang, I saw some Intel-type processes in the monitor. Not only Erlang, but also Python code had some strange phenomena. After uninstalling and reinstalling Homebrew, I reinstalled all language environments such as Python and Erlang, and the problem was solved. I hope this experience can be helpful to you.

Coelepinda

Coelepinda

I had the same problem trying to run elixir for the first time (very frustrating). I’m using an m1 chip on macOS Sanoma. As suggested here before, it was most probably an architecture problem because after removing elixir again:

brew uninstall elixir
and reinstalling it forcing the architecture to be arm64:
arch -arm64 brew install elixir it worked for me!

I noticed that brew was using rosetta 2 since brew config gave back Rosetta 2: true. Simple fix and nice if it helps some other people aswell :slight_smile:.

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New

Other popular topics Top

vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

We're in Beta

About us Mission Statement