`Jason.Encoder is not available, cannot derive Jason.Encoder` using `mix compile.elixir`


I am trying out the script from dashbits new blogpost https://dashbit.co/blog/rewriting-imports-to-aliases-with-compilation-tracers on my project.

They use the compile.elixir task in there. I can’t get this task to run on my project, while mix compile runs just fine. The errors I keep getting with compile.elixir all are ** (ArgumentError) Jason.Encoder is not available, cannot derive Jason.Encoder at various places in my code where I derive Jason.Encoder.

Anybody got any idea if this is expected behavior, an error on my side or a bug?

In case someone runs into the same problems I have run into:

  1. If you derive Protocols of external dependencies like Jason.Encoder, for compile.elixir to work, you need to first run mix compile.protocols
  2. Unlike stated here https://dashbit.co/blog/rewriting-imports-to-aliases-with-compilation-tracers, it seems like you need to use mix run import2alias.exs ... instead of elixir import2alias.exs ... otherwise the will be no mix environment (af far as I understand) and you’ll get this error: ** (exit) exited in: GenServer.call(Mix.ProjectStack, {:get_stack, #Function<10.68469381/1 in Mix.ProjectStack.peek/0>}, :infinity). At least that worked for me.