Search code examples
elixirphoenix-frameworkelixir-mix

Erlang package failing to load


I'm trying to use an Erlang package (this one : https://github.com/komone/qrcode) inside my Phoenix project, so I'm simply trying to get it from my mix file :

  defp deps do
    [{:phoenix, "~> 1.3.0-rc"},
     {:phoenix_pubsub, "~> 1.0"},
     {:phoenix_ecto, "~> 3.2"},
     {:postgrex, ">= 0.0.0"},
     {:gettext, "~> 0.11"},
     {:cowboy, "~> 1.0"},
     {:comeonin, "~> 3.0"},
     {:uuid, "~> 1.1"},
     {:timex, "~> 3.1"},
     {:timex_ecto, "~> 3.1"},
     {:porcelain, "~> 2.0"},
     {:qrcode, git: "https://github.com/komone/qrcode"}, # <--
     {:credo, "~> 0.7", only: [:dev, :test]}]
  end

I had to manually erl -make inside the fetched directory to make it compile, but at phoenix startup I get the following error :

** (Mix) Could not start application qrcode: exited in: :qrcode.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function :qrcode.start/2 is undefined or private
            (qrcode) :qrcode.start(:normal, [])
            (kernel) application_master.erl:273: :application_master.start_it_old/4

Is there another step to do to make it work ?


Solution

  • Just found the convenient mix option to pass :

    {:qrcode, git: "https://github.com/komone/qrcode", app: false}
    

    in order to prevent Mix from trying to load the package application file.

    https://hexdocs.pm/mix/Mix.Tasks.Deps.html

    Note : you can use the :compile option to get rid of the manual compilation of an Emakefile package, in this case :

    {:qrcode, git: "https://github.com/komone/qrcode", app: false, compile: "erl -make"}