flodihn

flodihn

Running elixir from Erlang release

Hello, I am creating a project where I mix Erlang and Elixir applications.
I can do this when running Erlang by executing erl manually from my bash shell and adding the path to the elixir installation using the Erlangs code module, like this:

$> erl
Erlang/OTP 24 [erts-12.0] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]
Eshell V12.0  (abort with ^G)
1> application:start(compiler).
ok
2> code:add_path("/usr/local/lib/elixir/lib/elixir/ebin").
true
3> application:start(elixir).
ok

However, when I do the exact same inside a release that I built with rebar3, it seems like the VM can not execute any code, even if it finds the elixir.app file.

$>bin/ao_devserver console
Erlang/OTP 24 [erts-12.0] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:30] [jit]
Eshell V12.0  (abort with ^G)
(ao_devserver@pop-os)1> application:start(compiler).
{error,{already_started,compiler}}
(ao_devserver@pop-os)2> code:add_path("/usr/local/lib/elixir/lib/elixir/ebin").
true
(ao_devserver@pop-os)3> application:start(elixir).
=CRASH REPORT==== 24-Apr-2022::06:19:38.775000 ===
  crasher:
    initial call: application_master:init/4
    pid: <0.998.0>
    registered_name: []
    exception exit: {bad_return,
                        {{elixir,start,[normal,[]]},
                         {'EXIT',
                             {undef,
                                 [{elixir,start,[normal,[]],[]},
                                  {application_master,start_it_old,4,
                                      [{file,"application_master.erl"},
                                       {line,293}]}]}}}}
      in function  application_master:init/4 (application_master.erl, line 142)
    ancestors: [<0.997.0>]
    message_queue_len: 1
    messages: [{'EXIT',<0.999.0>,normal}]
    links: [<0.997.0>,<0.791.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 987
    stack_size: 29
    reductions: 156
  neighbours:

=INFO REPORT==== 24-Apr-2022::06:19:38.776020 ===
    application: elixir
    exited: {bad_return,
                {{elixir,start,[normal,[]]},
                 {'EXIT',
                     {undef,
                         [{elixir,start,[normal,[]],[]},
                          {application_master,start_it_old,4,
                              [{file,"application_master.erl"},
                               {line,293}]}]}}}}
    type: temporary

{error,
    {bad_return,
        {{elixir,start,[normal,[]]},
         {'EXIT',
             {undef,
                 [{elixir,start,[normal,[]],[]},
                  {application_master,start_it_old,4,
                      [{file,"application_master.erl"},{line,293}]}]}}}}}

I spent two evenings trying to figure this out, reading on stack-overflow, these forums etc but could not find anyone with same problem as me, maybe I am doing it wrong?

Marked As Solved

flodihn

flodihn

Your wise council belies your years Mr. Valim.

Indeed my problem was that the script which runs the release starting erlang in embedded mode:
erl -mode embedded

If someone in the future experience the same problem, I am glad to let you know that this can be controlled by setting the CODE_LOADING_MODE environment variable and then calling the release start script:

export CODE_LOADING_MODE=-interactive

./bin/ao_devserver console
(ao_devserver@pop-os)1> code:add_path("/usr/local/lib/elixir/lib/elixir/ebin/").
true
(ao_devserver@pop-os)2> application:start(elixir).
ok
(ao_devserver@pop-os)3>

Also Liked

LostKobrakai

LostKobrakai

More a workaround to your issue, but mix can compile erlang and elixir source code side by side (lib folder for elixir code, src for erlang code).

josevalim

josevalim

Creator of Elixir

Your release is likely running in embedded mode, which means code is not loaded interactively.

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&amp;query=perfume&amp;page=2, I would like to get: ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
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
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
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
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43657 311
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31194 112
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52774 488
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
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
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

We're in Beta

About us Mission Statement