OTP - Adding Couchbeam as a dependency - ** exception error: undefined function jsx:decode/1

433 views Asked by At

I'm using rebar to get/compile my dependencies which has the following in rebar.conf:

{deps, [
    ...
    {couchbeam, ".*", {git, "git://github.com/benoitc/couchbeam.git", {branch, "master"}}}
  ]}.

then I use relx to generate the release. relx.config has:

{release, {myapp, "0.0.1"}, [myapp, couchbeam]}.
{extended_start_script, true}.

myapp.app.src:

{application, myapp,
 [                             
  {description, ""},           
  {vsn, "1"},
  {registered, []},            
  {applications, [             
                  kernel,      
                  stdlib,  

                  ... ,

                  couchbeam    
                 ]},
  {mod, { myapp_app, []}},    
  {env, []}
 ]}.

having started couchdb, I run my release under console and try to test couchbeam with the following lines:

Host = "localhost",
Port = 5984,
Prefix = "",
Options = [],
S = couchbeam:server_connection(Host, Port, Prefix, Options).
{ok, _Version} = couchbeam:server_info(S).

the last line gives me the error: ** exception error: undefined function jsx:decode/1


To solve this, I opened deps/couchbeam/couchbeam.app.src and changed:

 {applications, [kernel,
                  stdlib,
                  asn1,
                  crypto,
                  public_key,
                  ssl,
                  idna,
                  hackney
                  ]},

and added jsx:

{applications, [kernel,
                  stdlib,
                  asn1,
                  crypto,
                  public_key,
                  ssl,
                  idna,
                  hackney,
                  jsx
                  ]},

Is there something wrong in my setup of how I added couchbeam as a dependency? I feel like I'm not supposed to hack the .app.src of one of my dependencies

1

There are 1 answers

1
Viacheslav Kovalev On BEST ANSWER

My suggestion is that couchbeam doesn't include jsx as application-level dendency (in .app.src file) because it can work with different json encoders (actually only with jsx and jiffy). So, you should decide which one exactly to use by your own.

Since neither couchbeam nor your application doesn't provide any information about this depedency, relx doesn't include jsx in release.

Confess, I didn't try, but I think your solution is to define jsx as dependency of your own application (i.e., add it to your own .app.src file instead of couchbeam.app.src).