Mix phx.gen.json fails with `module Jason is not available`

Im on arch, installed elixir-git from AUR

mix phx.gen.json Web Item items code:text name:text --web Api
* creating lib/hp_web/controllers/api/classifier_controller.ex
* creating lib/hp_web/views/api/classifier_view.ex
** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
    Jason.encode!("some code")
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
    (stdlib) erl_eval.erl:888: :erl_eval.expr_list/6
    (stdlib) erl_eval.erl:411: :erl_eval.expr/5
    (stdlib) erl_eval.erl:888: :erl_eval.expr_list/6
    (stdlib) erl_eval.erl:411: :erl_eval.expr/5
    (stdlib) erl_eval.erl:449: :erl_eval.expr/5
    (stdlib) erl_eval.erl:126: :erl_eval.exprs/5

mix archive 
* hex-0.20.1
* phoenix-1.4.9
* phx_new-1.4.9
mix --version 
Erlang/OTP 22 [erts-10.4.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Mix 1.9.0 (compiled with Erlang/OTP 22
elixir --version 
Erlang/OTP 22 [erts-10.4.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.9.0 (compiled with Erlang/OTP 22)
  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [
      mod: {Hp.Application, []},
      extra_applications: [:logger, :runtime_tools]
    ]
  end

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
    [
      {:phoenix, "~> 1.4.9"},
      {:phoenix_pubsub, "~> 1.1"},
      {:phoenix_ecto, "~> 4.0"},
      {:ecto_sql, "~> 3.1"},
      {:postgrex, ">= 0.0.0"},
      {:gettext, "~> 0.11"},
      {:jason, "~> 1.0"},
      {:plug_cowboy, "~> 2.0"}
    ]
  end

Did you try installing Erlang and Elixir through asdf?

Is there any reason you do not use community/elixir?

If it is just because of the version available, then I’d suggest to actually fetch the package description from the Arch Build System and change the pkgver in th PKGBUILD to any version you like, also its good practice to set pkgrel=0 then, you’ll get upstream updates then as they are available.

elixir-git from the AUR always fetches master branch and therefore might be in some state that is not usable.

1 Like

as I can remember community/elixir provides mix without release command and since Im newb to this stuff I installed elixir-git to release my first phoenix app. But now Im installing asdf version of erlang/elixir to check if it will work for me.

mix release has been added with elixir 1.9, and latest on community/elixir is 1.8.2, so yes, it comes without it. Thats why I suggested to manually build from ABS.

But yes, asdf-vm is also a good option. You should though remove the faulty build installed through elixir-git.

To be honest, you rarely want to actually use a VCS-package from the AUR unless you really know what you are doing.

mix phx.gen.json Web Classifier classifiers name:string code:string --web Api 
* creating lib/hp_web/controllers/api/classifier_controller.ex
* creating lib/hp_web/views/api/classifier_view.ex
** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
    Jason.encode!("some code")
    (stdlib 3.9) erl_eval.erl:680: :erl_eval.do_apply/6
    (stdlib 3.9) erl_eval.erl:888: :erl_eval.expr_list/6
    (stdlib 3.9) erl_eval.erl:411: :erl_eval.expr/5
    (stdlib 3.9) erl_eval.erl:888: :erl_eval.expr_list/6
    (stdlib 3.9) erl_eval.erl:411: :erl_eval.expr/5
    (stdlib 3.9) erl_eval.erl:449: :erl_eval.expr/5
    (stdlib 3.9) erl_eval.erl:126: :erl_eval.exprs/5

asdf
elixir master-otp-22
erlang 22.0-rc3

Have you already removed the faulty installation from the AUR, and/or did you change your asdfs default after installation?

Of course, Im always removing old installations.

What’s asdf’s defaults? Do you mean running asdf global/local? I did asdf global for both erlang and elixir packages

Hmmm…

Please remove the _build and deps folder from your project and redownload/compile dependencies.

After asdf install I created new project from scratch

Hmmm…

This is weird… Though I’m not even sure anymore if its really because of your elixir version…

Anyway, lets check your installation, what does which elixir print you? And $(which elixir) --version?

[ar7max@anarchy]: ~/projects/hp>$ which elixir
/home/ar7max/.asdf/shims/elixir
[ar7max@anarchy]: ~/projects/hp>$ $(which elixir) --version
Erlang/OTP 22 [RELEASE CANDIDATE 3] [erts-10.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.10.0-dev (99f504e) (compiled with Erlang/OTP 22)

Oh, its 1.10 but error is the same

How have you installed that one? What is the contents of your .tool-version in that project?

I installed elixir master-otp-22 and that’s all I saw in asdf output. So I guess that’s ok.
I can’t find any .tool-version file on my whole system

Please do not install from master unless you really know what you are doing, stick to official releases.

A .tool-version file is generated once you do asdf local …

1 Like

But I did asdf global

Seems like you never called mix deps.get.

This explains why you haven’t such a file :wink: Still, get rid of the master build and use official 1.9.1.

2 Likes

elixir 1.9.1-otp-22

worked for me, thanks

1 Like