Pratima Chainani
Pratima Chainani

Reputation: 31

Load/Recompile Rebar Modules after downgrading Erlang/OTP

I wish to use an erlang client library to communicate with an mqtt broker for one of my projects. So I've started an application using rebar3's built-in templates and added emqttc as a dependency. Since erlang/otp 21 does not have support for gen_logger(emqttc depends on gen_logger) and the tuple_calls compiler options do not suffice, I had to downgrade to erlang@20 according to this post.

Now the issue with downgrading erlang is that, none of rebar3's commands(clean/compile/shell/report etc) work as expected and my previous projects built with rebar3 do not compile, I get to see this error message:

=ERROR REPORT==== 21-Aug-2018::12:54:29 === Loading of /usr/local/bin/rebar3/rebar/ebin/rebar3.beam failed: badfile escript: exception error: undefined function rebar3:main/1 in function escript:run/2 (escript.erl, line 759) in call from escript:start/1 (escript.erl, line 277) in call from init:start_em/1 in call from init:do_boot/3

=ERROR REPORT==== 21-Aug-2018::12:54:29 === beam/beam_load.c(1863): Error loading module rebar3: This BEAM file was compiled for a later version of the run-time system than 20. To fix this, please recompile this module with an 20 compiler. (Use of opcode 160; this emulator supports only up to 159.)

I've uninstalled and reinstalled rebar3, looked up on the web for this but nothing's clear and specific to rebar. Any help on this would be appreciated.

Upvotes: 3

Views: 3535

Answers (2)

manu datta
manu datta

Reputation: 151

Check your _build/prod/rel/YOURAPPNAME/ directory. Most probably it has a release which doesn't match your erlang version. You can safely delete this directory and rebuild using rebar3 compile

Upvotes: 1

Sachith Muhandiram
Sachith Muhandiram

Reputation: 2972

This may not be the exact answer for your question. But it may give you and idea.

What about using Docker. Its an easy way to keep your environment clean and neat.

If you use docker, you just have to include your new erlang version in Dockerfile as an environment variable.

ENV OTP_VERSION="20.3.6"

Upvotes: 2

Related Questions