Jason fails to compile when MIX_ENV=prod

Hello!

I’m trying to set up a small Elixir app that depends on jason via another package. Using mix release works, but as soon as I set MIX_ENV=prod I get one of the following errors, nondeterministically:

→ MIX_ENV=prod mix release
==> jason
Compiling 10 files (.ex)

== Compilation error in file lib/encode.ex ==
** (SyntaxError) invalid syntax found on lib/encode.ex:318:57:
     error: unexpected token: "\" (column 57, code point U+005C)
     │
 318 │   slash_escapes = Enum.zip(~c"\b\t\n\f\r\\"\\", ~c"btnfr\"\\")
     │                                                         ^
     │
     └─ lib/encode.ex:318:57
    (elixir 1.16.0) lib/kernel/parallel_compiler.ex:428: anonymous fn/5 in Kernel.ParallelCompiler.spawn_workers/8
could not compile dependency :jason, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile jason --force", update it with "mix deps.update jason" or clean it with "mix deps.clean jason"
→ MIX_ENV=prod mix release
==> jason
Compiling 10 files (.ex)

== Compilation error in file lib/decoder.ex ==
** (SyntaxError) invalid syntax found on lib/decoder.ex:825:24:
     error: unexpected token: "\" (column 24, code point U+005C)
     │
 825 │        when byte in ~c"\s\n\r\t" do
     │                        ^
     │
     └─ lib/decoder.ex:825:24
    (elixir 1.16.0) lib/kernel/parallel_compiler.ex:428: anonymous fn/5 in Kernel.ParallelCompiler.spawn_workers/8
could not compile dependency :jason, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile jason --force", update it with "mix deps.update jason" or clean it with "mix deps.clean jason"

I’ve looked at the code in jason and it looks innocuous:

  slash_escapes = Enum.zip(~c"\b\t\n\f\r\\"\\", ~c"btnfr\"\\")

Does MIX_ENV=prod change something about the Elixir language?

@jyc I don’t know what the problem is, but what’s the verison of Jason that is being pulled in? Also, I can see Elixir 1.16.0, but what about Erlang?

My first step when weird stuff like this happens is to delete the _build directory and try again.

Also, what version of Erlang OTP are you using? Does the error still occur if you use a newer/older version of OTP? How about an older version of Elixir? Which platform are you on? (Linux, Mac, Windows)

1 Like

Also Jason, if it’s being pulled by some library it may require an old version, and installing, oven with override: true to use newer version may solve it.

Thanks both for the reply! Sorry for not including the version numbers @hubertlepicki.

Erlang/OTP 26 [erts-14.2.1] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] [dtrace]
Elixir 1.16.0 (compiled with Erlang/OTP 26)

deps/jason/mix.exs says it’s 1.4.1. I’m on macOS.

However, I tried @arcanemachine’s suggestion of rm -rf _build and bizarrely it worked! Very strange. It’s good to know but I wonder how that situation happened.

Also thanks for the tip about using override: true, will remember that!

1 Like

Glad that helped. I literally had the same thing happen yesterday. (It’s not a common occurrence, but it has happened to me before.)

1 Like

You will have an improved QOL if you don’t wonder such things :upside_down_face:

2 Likes