rebar3 undef when running release console

150 Views Asked by At

I've been playing around with rebar3 (3.15.0) just to get it to run with the basic templates, and running into issues just trying to get a simple Hello World type example program going. I am starting with the template command to build a new release:
rebar3 new release myfirstproj.

It works fine when I run rebar3 shell but gives me the error below when running the release command:
myfirstproj.cmd console after building it with rebar3 release.

The only thing I've added to the base template is a io:format("Hello world!") in the supervisor.. It seems like the undef below is indicating it can't find the myfirstproj_app:start function.. any ideas why it doesn't work here but works in the rebar3 shell?

OTP 23 [erts-11.0] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:30]

=CRASH REPORT==== 21-Apr-2021::22:39:52.740000 ===
  crasher:
    initial call: application_master:init/4
    pid: <0.85.0>
    registered_name: []
    exception exit: {bad_return,
                        {{myfirstproj_app,start,[normal,[]]},
                         {'EXIT',
                             {undef,
                                 [{myfirstproj_app,start,[normal,[]],[]},
                                  {application_master,start_it_old,4,
                                      [{file,"application_master.erl"},
                                       {line,277}]}]}}}}
      in function  application_master:init/4 (application_master.erl, line 138)
    ancestors: [<0.83.0>]
    message_queue_len: 1
    messages: [{'EXIT',<0.85.0>,normal}]
    links: [<0.83.0>,<0.44.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 376
    stack_size: 28
    reductions: 224
  neighbours:

=INFO REPORT==== 21-Apr-2021::22:39:21.439000 ===
    application: myfirstproj
    exited: {bad_return,
                {{myfirstproj_app,start,[normal,[]]},
                 {'EXIT',
                     {undef,
                         [{myfirstproj_app,start,[normal,[]],[]},
                          {application_master,start_it_old,4,
                              [{file,"application_master.erl"},
                               {line,277}]}]}}}}
    type: permanent

My app code hasn't been changed from the template:

%%%-------------------------------------------------------------------
%% @doc myfirstproj public API
%% @end
%%%-------------------------------------------------------------------

-module(myfirstproj_app).

-behaviour(application).

-export([start/2, stop/1]).

start(_StartType, _StartArgs) ->
    myfirstproj_sup:start_link().

stop(_State) ->
    ok.

%% internal functions

Same with my app.src:

{application, myfirstproj,
 [{description, "An OTP application"},
  {vsn, "0.1.0"},
  {registered, []},
  {mod, {myfirstproj_app, []}},
  {applications,
   [kernel,
    stdlib
   ]},
  {env,[]},
  {modules, []},

  {licenses, ["Apache 2.0"]},
  {links, []}
 ]}.

The rebar.config hasn't been modified from the template.

myfirstproj_sup.erl:

%%%-------------------------------------------------------------------
%% @doc myfirstproj top level supervisor.
%% @end
%%%-------------------------------------------------------------------

-module(myfirstproj_sup).
-behaviour(supervisor).
-export([start_link/0]).
-export([init/1]).
-define(SERVER, ?MODULE).

start_link() ->
    io:format("Hey, we started!"),
    supervisor:start_link({local, ?SERVER}, ?MODULE, []).

init([]) ->
    SupFlags = #{strategy => one_for_all,
                 intensity => 0,
                 period => 1},
    %ChildSpecs = [{worker1,
        %{file_watcher, start_link, []}, permanent, 1000, worker, [file_watcher]}],
    ChildSpecs = [],
    {ok, {SupFlags, ChildSpecs}}.

%% internal functions
1

There are 1 best solutions below

0
On

I ran into this issue using rebar3 v3.22.1 on Windows. With default settings (no changes to generated rebar.config) rebar3 release creates a dev mode release, which means it creates symlinks to your compiled files instead of copying them, so that any changes you compile are automatically used by the release (after restart, but without re-releasing). However, it turns out those symlinks don't work well under Windows. Even with access rights sorted out properly, running <releasename> console or <releasename> start ends with the same error as OP described (undef releasename:start/2).

In my case it helped to switch to production releases, by modyfing rebar.config to say {mod, prod} (or {dev_mode, false}). Both <releasename> console and <releasename> start worked properly after this change.