wktdev

wktdev

How do I fix this error when trying to create an "Application": (UndefinedFunctionError) function App.start/2 is undefined

I tried to learn Elixir a few years ago and stopped. I am trying again.
In the code below I have a GenServer that is started by a Supervisor. When I compile the code it works as expected - if the GenServer is manually killed the Supervisor restarts it.

This is good and does what I expect.

I now want to wrap my code as an “Application”.

Thus I go to mix.exs and in the application method I update the code to reference my Module

def application do
    [
      extra_applications: [:logger],
      mod: {App, []}
    ]
  end

When I compile my code I get the following error:

18:49:32.437 [notice] Application todos exited: exited in: App.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function App.start/2 is undefined (module App is not available)
            App.start(:normal, [])
            (kernel 8.5) application_master.erl:293: :application_master.start_it_old/4
** (Mix) Could not start application todos: exited in: App.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function App.start/2 is undefined (module App is not available)
            App.start(:normal, [])
            (kernel 8.5) application_master.erl:293: :application_master.start_it_old/4

I am not sure what the error is inferring is wrong nor do I know how to fix it. I would like to know how to fix it and why the error occurs.

My full code is below

todos/lib/todos.ex




defmodule App.Service do
  use GenServer

  def start_link(state) do
    GenServer.start_link(__MODULE__, state, name: __MODULE__)
  end

  def init(state) do
     {:ok, state}
  end

  def get_state(pid) do
     GenServer.call(pid, :get_state)
  end

  def set_state(pid,state) do
     GenServer.call(pid, {:set_state, state})
  end


  def handle_call(:get_state, _from, state) do
     {:reply, state, state}
  end


  def handle_call({:set_state, new_state}, _from, state)do
    {:reply,state,[new_state | state]}
  end
   
end

defmodule App.Supervisor do
  use Supervisor

  def start do
    Supervisor.start_link(__MODULE__, [])
  end

  def init(_) do
     children = [
      {App.Service,[]}
     ]
  Supervisor.init(children, strategy: :one_for_one)
  end
end

todos/lib/mix.exs


defmodule Todos.MixProject do
  use Mix.Project

  def project do
    [
      app: :todos,
      version: "0.1.0",
      elixir: "~> 1.14",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  def application do
    [
      extra_applications: [:logger],
      mod: {App, []}
    ]
  end

  defp deps do
    [
    ]
  end
end

Most Liked

derek-zhou

derek-zhou

An application need to implement the Application behavior. You may want to see what the mix generator generate for you:

mix new hello_world --sup

And start from there.

Where Next?

Popular in Troubleshooting Top

alexlanderzander
Hello everyone, I’m working on a blockchain project in Elixir and I’m implementing some of the core cryptography in a Rust NIF using Rus...
New
chocolatedonut
Besides (over)logging every code-path leading to Repo.insert_all, is it possible to make Postgrex and/or ecto_sql log the exact, failing ...
New
wktdev
I tried to learn Elixir a few years ago and stopped. I am trying again. In the code below I have a GenServer that is started by a Superv...
New
harmon25
Hi All, I am bumping into a weird issue with an umbrella app while upgrading to latest Elixir 1.19.x + otp28. A couple apps in the umbr...
New
pikdum
Hello, I’m trying to upgrade a pretty large project from Elixir 1.18.4 to Elixir 1.19.1 (1321 modules), but seeing some compiler warning...
New
jason.o
I don’t get an error directly related to Paraxial, but removing that dependency stopped the crash. Has anyone experienced a similar issu...
New
Richardm
Hi, I have the following code, and even though I can see (via the inspect) that the response_body does contain one of the strings I’m lo...
New
onelastdance
Hey there, Using the install script method recommended here on Ubuntu 24.04: And then running the following commands: iex> :obser...
New
rayex
Hi, I am using the following versions: Erlang/OTP 27 [erts-15.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns] El...
New
apoorv-2204
The Issue of Enums in Elixir Elixir doesn’t have a native enum construct, so we usually rely on atoms, strings, or macros to represent na...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

We're in Beta

About us Mission Statement