Error using dependency at compile time

Hey everyone!

I’m having a hard time understanding why I can’t use Jason at compile time. This is a library I forked, and it’s randomly causing issues with other libraries it depends on.

The issue is in this line, and the error is:

❯ mix test
Compiling 2 files (.ex)

== Compilation error in file lib/exmoji.ex ==
** (UndefinedFunctionError) function Jason.decode!/2 is undefined (module Jason is not available)
    (jason 1.4.4) Jason.decode!("[{\"name\":\"COPYRIGHT SIGN\",\"unified\":\"00A9\",\"variations\":[],\"docomo\":\"E731\",\"au\":\"E558\",\"softbank\":\"E24E\",\"google\":\"FEB29\",\"image\":\"00a9.png\",\"sheet_x\":0,\"sheet_y\":0,\"short_name\":\"copyright\",\"short_names\":[\"copyright\"],\"text\":null,\"apple_img\":true,\"hangouts_img\":true,\"twitter_img\":false},{\"name\":\"REGISTERED SIGN\",\"unified\":\"00AE\",\"variations\":[],\"docomo\":\"E736\",\"au\":\"E559\",\"softbank\":\"E24F\",\"google\":\"FEB2D\",\"image\":\"00ae.png\",\"sheet_x\":0,\"sheet_y\":1,\"short_name\":\"registered\",\"short_names\":[\"registered\"],\"text\":null,\"apple_img\":true,\"hangouts_img\":true,\"twitter_img\":false},{\"name\":\"DOUBLE EXCLAMATION MARK\",\"unified\":\"203C\",\"variations\":[\"203C-FE0F\"],\"docomo\":\"E704\",\"au\":\"EB30\",\"softbank\":null,\"google\":\"FEB06\",\"image\":\"203c.png\",\"sheet_x\":0,\"sheet_y\":2,\"short_name\":\"bangbang\",\"short_names\":[\"bangbang\"],\"text\":null,\"apple_img\":true,\"hangouts_img\":true,\"twitter_img\":true},{\"name\":\"EXCLAMATION QUESTION MARK\",\"unified\":\"2049\",\"variations\":[\"2049-FE0F\"],\"docomo\":\"E703\",\"au\":\"EB2F\",\"softbank\":null,\"google\":\"FEB05\",\"image\":\"2049.png\",\"sheet_x\":0,\"sheet_y\":3,\"short_name\":\"interrobang\",\"short_names\":[\"interrobang\"],\"text\":null,\"apple_img\":true,\"hangouts_img\":true,\"twitter_img\":true},{\"name\":\"TRADE MARK SIGN\",\"unified\":\"2122\",\"variations\":[],\"docomo\":\"E732\",\"au\":\"E54E\",\"softbank\":\"E537\",\"google\":\"FEB2A\",\"image\":\"2122.png\",\"sheet_x\":0,\"sheet_y\":4,\"short_name\":\"tm\",\"short_names\":[\"tm\"],\"text\":null,\"apple_img\":true,\"hangouts_img\":true,\"twitter_img\":true},{\"name\":\"INFORMATION SOURCE\",\"unified\":\"2139\",\"variations\":[\"2139-FE0F\"],\"docomo\":null,\"au\":\"E533\",\"softbank\":null,\"google\":\"FEB47\",\"image\":\"2139.png\",\"sheet_x\":0,\"sheet_y\":5,\"short_name\":\"information_source\",\"short_names\":[\"information_source\"],\"text\":null,\"apple_img\":true,\"hangouts_img\":true,\"twitter_img\":true},{\"name\":\"LEFT RIGHT ARROW\",\"unified\":\"2194\",\"variations\":[\"2194-FE0F\"],\"docomo\":\"E73C\",\"au\":\"EB7A\",\"softbank\":null,\"google\":\"FEAF6\",\"image\":\"2194.png\",\"sheet_x\":0,\"sheet_y\":6,\"short_name\":\"left_right_arrow\",\"short_names\":[\"left_right_arrow\"],\"text\":null,\"apple_img\":true,\"hangouts_img\":true,\"twitter_img\":true},{\"name\":\"UP DOWN ARROW\",\"unified\":\"2195\",\"variations\":[\"2195-FE0F\"],\"docomo\":\"E73D\",\"au\":\"EB7B\",\"softbank\":null,\"google\":\"FEAF7\",\"image\":\"2195.png\",\"sheet_x\":0,\"sheet_y\":7,\"short_name\":\"arrow_up_down\",\"short_names\":[\"arrow_up_down\"],\"text\":null,\"apple_img\":true,\"hangouts_img\":true,\"twitter_img\":true},{\"name\":\"NORTH WEST ARROW\",\"unified\":\"2196\",\"variations\":[\"2196-FE0F\"],\"docomo\":\"E697\",\"au\":\"E54C\",\"softbank\":\"E237\",\"google\":\"FEAF2\",\"image\":\"2196.png\",\"sheet_x\":0,\"sheet_y\":8,\"short_name\":\"arrow_upper_left\",\"short_names\":[\"arrow_upper_left\"],\"text\":null,\"apple_img\":true,\"hangouts_img\":true,\"twitter_img\":true},{\"name\":\"NORTH EAST ARROW\",\"unified\":\"2197\",\"variations\":[\"2197-FE0F\"],\"docomo\":\"E678\",\"au\":\"E555\",\"softbank\":\"E236\",\"google\":\"FEAF0\",\"image\":\"2197.png\",\"sheet_x\":0,\"sheet_y\":9,\"short_name\":\"arrow_upper_right\",\"short_names\":[\"arrow_upper_right\"],\"text\":null,\"apple_img\":true,\"hangouts_img\":true,\"twitter_img\":true},{\"name\":\"SOUTH EAST ARROW\",\"unified\":\"2198\",\"variations\":[\"2198-FE0F\"],\"docomo\":\"E696\",\"au\":\"E54D\",\"softbank\":\"E238\",\"google\":\"FEAF1\",\"image\":\"2198.png\",\"sheet_x\":0,\"sheet_y\":10,\"short_name\":\"arrow_lower_right\",\"short_names\":[\"arrow_lower_right\"],\"text\":null,\"apple_img\":true,\"hangouts_img\":true,\"twitter_img\":true},{\"name\":\"SOUTH WEST ARROW\",\"unified\":\"2199\",\"variations\":[\"2199-FE0F\"],\"docomo\":\"E6A5\",\"au\":\"E556\",\"softbank\":\"E239\",\"google\":\"FEAF3\",\"image\":\"2199.png\",\"sheet_x\":0,\"sheet_y\":11,\"short_name\":\"arrow_lower_left\",\"short_names\":[\"arrow_lower_left\"],\"text\":null,\"apple_img\":true,\"hangouts_img\":true,\"twitter_img\":true},{\"name\":\"LEFTWARDS ARROW WITH HOOK\",\"unified\":\"21A9\",\"variations\":[\"21A9-FE0F\"],\"docomo\":\"E6DA\",\"au\":\"E55D\",\"softbank\":null,\"google\":\"FEB83\",\"image\":\"21a9.png\",\"sheet_x\":0,\"sheet_y\":12,\"short_name\":\"leftwards_arrow_with_hook\",\"short_names\":[\"leftwards_arrow_with_hook\"],\"text\":null,\"apple_img\":true,\"hangouts_img\":true,\"twitter_img\":true},{\"name\":\"RIGHTWARDS ARROW WITH HOOK\",\"unified\":\"21AA\",\"variations\":[\"21AA-FE0F\"],\"docomo\":null,\"au\":\"E55C\",\"" <> ..., [keys: :atoms])
    lib/exmoji.ex:26: (module)

Any clue what I’m doing wrong? Thanks!

I would first of all change to :ok = Application.ensure_loaded(:jason) to at least know that the application is loaded.

Secondly, I would take a look at the output of mix compile --force and check that you can see :jason being compiled before your module.

If it is compiled first, but you are still getting that error, I would typically add {:module, _module} = Code.ensure_loaded(Jason) before I use the module to make sure that it is loaded.

If that fails - perhaps because :jason hasn’t been compiled before your module uses it - you might need to use the last result of Code.ensure_compiled/1.

2 Likes

The problem is in your mix.exs file.

Currently it has:

def application do
    [applications: []]
end

You should change the applications key to extra_applications.

3 Likes