flodihn

flodihn

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?

Showing Posts 1 to 5

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).

flodihn

flodihn OP

I made some progress, I discovered that starting my release with as “console_clean”, I can start the elixir application with no errors:

bin/ao_devserver console_clean
Exec: /usr/local/lib/erlang/erts-12.0/bin/erlexec -boot 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).
ok
(ao_devserver@pop-os)2> application:start(elixir).  
{error,{"no such file or directory","elixir.app"}}
(ao_devserver@pop-os)3> code:add_path("/usr/local/lib/elixir/lib/elixir/ebin").
true
(ao_devserver@pop-os)4> application:start(elixir).                             
ok
(ao_devserver@pop-os)5>

I have yet not discovered exactly why yet but it has to do with some of the difference in the start parameters from the starting with just “console”.

josevalim

josevalim

Creator of Elixir

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

flodihn

flodihn OP

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>
mau5atron

mau5atron

Hello from the future!

I posted something similar on ErlangForums earlier today and rephrased my google search enough to have found the solution posted here.

My post here: Adding elixir dependencies to an Erlang+Cowboy application - Questions / Help - Erlang Programming Language Forum - Erlang Forums

Adding export CODE_LOADING_MODE=-interactive to my shell env fixed my issue and I’m able to load Elixir into my Cowboy application shell. My next venture is to try to use elixir in my Erlang code.

Thank you @josevalim and @flodihn :grinning:

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews