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

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
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
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
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
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
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
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
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
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
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
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

We're in Beta

About us Mission Statement