Module is undefined

My mix file:

   defp deps do
    [.............
     {:qrcode, git: "git@gitlab.com:Pacodastre/qrcode.git"},

Controller:

res = :qrcode.encode(data) |> :qrcode_demo.simple_png_encode()

All of a sudden it’s started failing on a server with the error

** (UndefinedFunctionError) function :qrcode.encode/1 is undefined (module :qrcode is not available)

But locally it works. And it used to work on a server.

Adding :qrcode to

def application do
    [mod: {MyApp, []},
     applications: [:qrcode, ...

throws an exception.

1 Like

Which?

1 Like

That it’s not needed there.

It used to work without that successfully, on a server and is working on a client.

1 Like
** (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
1 Like

But its app file tells it should be there:

  {mod, {qrcode, []}},

Please file a bug in that repository.

Unless you run your project via mix directly, you will need to specify it in :applications that it gets bundled in the artifact, and if the application has a mod key, it will be tried to properly started.

1 Like

If you’re using distillery, you could configure the qrcode app to be loaded, but not started as a workaround. This means you should omit it from the applications list in mix.exs and in the rel/config.exs in the relevant release block use:

set applictions: [app_name, qrcode: :load]

But yes, the package seems to be broken.

3 Likes

I have created an issue (#2) and a fixing MR (!2)

After there is already an uncommented MR which was intended to fix this issue for 9 months now, and a bug report telling about a similar problem as you since January '17, I do not expect my MR to get merged though.

Maybe I will find some time later to rebarize and hex that, but I have to check license as well first…

1 Like

But who did it manag to have been working well so far on my server?

1 Like
release :my_app do
  set version: current_version(:my_app)
  set applictions: [:my_app, qrcode: :load]
end

=====> when deploying…

==> Loading configuration..
** (Mix.Releases.Config.LoadError) could not load release config rel/config.exs
    ** (RuntimeError) unknown release config setting `applictions`
1 Like

Ok, that has been fixed. But

(UndefinedFunctionError) function :qrcode_demo.simple_png_encode/1 is undefined (module :qrcode_demo is not available)

even after I’ve added it to too:

set applications: [:my_app, qrcode: :load, qrcode_demo: :load]

1 Like

:qrcode_demo is not part of the :qrcode application (https://gitlab.com/Pacodastre/qrcode/blob/master/ebin/qrcode.app#L4). So it will not get bundled.

1 Like

then how to fix the error?

1 Like

Not use a module which is only provided as an example of usage…

1 Like

Then how to create a png file with a QR code?

qrcode = :qrcode.encode(“bla”)

# and what's the next?
1 Like

Implement :qrcode_demo.simple_png_encode/1 on your own. Or copy that file from the package to your own project into src/, mix will pick it up and distillery as well.

2 Likes