Fixing the compile error in Programming Phoenix source code

I'm working through the Programming Phoenix book for Elixir.

I hit a compile error with the source code that ships with the book. I use elixir installed with Homebrew.

== Compilation error on file web/router.ex ==
** (CompileError) web/router.ex: internal error in v3_core;
crash reason: {case_clause,
    {'EXIT',
        {badarg,
            [{erl_anno,anno_info,[-1],[{file,"erl_anno.erl"},{line,360}]},
             {v3_core,record_anno,2,[{file,"v3_core.erl"},{line,2410}]},
             {v3_core,expr,2,[{file,"v3_core.erl"},{line,539}]},
             {v3_core,safe,2,[{file,"v3_core.erl"},{line,1593}]},
             {v3_core,expr,2,[{file,"v3_core.erl"},{line,528}]},
             {v3_core,safe,2,[{file,"v3_core.erl"},{line,1593}]},
             {v3_core,'-safe_list/2-anonymous-0-',2,
                 [{file,"v3_core.erl"},{line,1608}]},
             {lists,foldr,3,[{file,"lists.erl"},{line,1276}]},
             {v3_core,expr,2,[{file,"v3_core.erl"},{line,538}]},
             {v3_core,safe,2,[{file,"v3_core.erl"},{line,1593}]},
             {v3_core,'-safe_list/2-anonymous-0-',2,
                 [{file,"v3_core.erl"},{line,1608}]},
             {lists,foldr,3,[{file,"lists.erl"},{line,1276}]},
             {v3_core,expr,2,[{file,"v3_core.erl"},{line,538}]},
             {v3_core,safe,2,[{file,"v3_core.erl"},{line,1593}]},
             {v3_core,expr,2,[{file,"v3_core.erl"},{line,528}]},
             {v3_core,safe,2,[{file,"v3_core.erl"},{line,1593}]},
             {v3_core,'-safe_list/2-anonymous-0-',2,
                 [{file,"v3_core.erl"},{line,1608}]},
             {lists,foldr,3,[{file,"lists.erl"},{line,1276}]},
             {v3_core,expr,2,[{file,"v3_core.erl"},{line,652}]},
             {v3_core,exprs,2,[{file,"v3_core.erl"},{line,512}]}]}}}

  in function  compile:'-select_passes/2-anonymous-2-'/2 (compile.erl, line 536)
  in call from compile:'-internal_comp/4-anonymous-1-'/2 (compile.erl, line 321)
  in call from compile:fold_comp/3 (compile.erl, line 347)
  in call from compile:internal_comp/4 (compile.erl, line 331)
  in call from compile:'-do_compile/2-anonymous-0-'/2 (compile.erl, line 179)
    (stdlib) lists.erl:1338: :lists.foreach/2
    (phoenix) expanding macro: Phoenix.Router.__before_compile__/1
    web/router.ex:9: Hello.Router (module)
    (elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1

This is because the example code uses packages that worked with erlang 18. But now Homebrew installs erlang 19 with the elixir formula.

The quickest way for getting stuck into the code from Programming Phoenix is to run elixir with erlang 18.

Install erlang 18 with:

brew install erlang@18

Follow the instructions from Homebrew to add it to the start of your PATH. This is so elixir finds erlang 18 before erlang 19.

To do this once off for bash run:

export PATH="/usr/local/opt/erlang@18/bin:$PATH

If are working on a real app, you'll want to upgrade the packages instead.

These issues helped me: