ydg33
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?
Marked As Solved
arcanemachine
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)
Also Liked
sodapopcan
You will have an improved QOL if you don’t wonder such things ![]()
ydg33
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!
arcanemachine
Glad that helped. I literally had the same thing happen yesterday. (It’s not a common occurrence, but it has happened to me before.)







