Mix test error in Elixir 1.4: "could not find application file"

I just upgraded to 1.4 and received the following error when I tried running my tests. My dev env compiles and runs successfully.

** (Mix) Could not start application http_server: could not find application file: http_server.app

http_server is a :test env dependency of my application dependency ExVCR. http_server is listed among my deps explicity.

I don’t get much more of an error than this, so this is the strack trace I’ve inferred:

elixir/lib/application.ex (Invoked from Application.format_error/1)

defp do_format_error({'no such file or directory', file}) do
    "could not find application file: #{file}"
  end

elixir/lib/kernel/cli.ex (Invoked from Kernel.CLI.main/1)

  defp process_command({:app, app}, _config) when is_binary(app) do
    case Application.ensure_all_started(String.to_atom(app)) do
      {:error, {app, reason}} ->
        {:error, "--app : Could not start application #{app}: " <>
          Application.format_error(reason)}
      {:ok, _} ->
        :ok
    end
  end

elixir/src/elixir.erl

start_cli() ->
  {ok, _} = application:ensure_all_started(?MODULE),

  %% We start the Logger so tools that depend on Elixir
  %% always have the Logger directly accessible. However
  %% Logger is not a dependency of the Elixir application,
  %% which means releases that want to use Logger must
  %% always list it as part of its applications.
  _ = case code:ensure_loaded('Elixir.Logger') of
{module, _} -> application:start(logger);
{error, _}  -> ok
  end,

  'Elixir.Kernel.CLI':main(init:get_plain_arguments()).

Once we get into Erlang territory, the .app suffix on http_server error starts to make sense. There is no such file anywhere in my project or the http_server dependency, so it’s where the trail runs cold for me.

I saw a similar ticket on github related to logger and escript bug and application dependencies in the application/0 function. ExVCR includes http_server in its mixfile application function (below). I know this is treated differently now in 1.4, which is the only reason I could think of as to why mix test is no longer working.

def application do
  [ applications: [:http_server] ]
end

I tried deleting my _build directory, mix.lockfile and all that, but nothing worked.

Any ideas what’s going on here?

1 Like

If you just specify in your mix.exs:

  defp deps do
    [{:exvcr, "~> 0.8"}]
  end

then in Elixir v1.4 this dependency will be automatically added to your application list (in Elixir v1.3 you had to do that explicitly). And so I believe the problem is that exvcr lists http_server as a dev/test dependency but also adds it to application list and so when mix fetches the dependency, it won’t grab http_server but since it’s in the application list Elixir will attempt to start it and fail.

Now, looking at exvcr docs, they don’t instruct to add exvcr to your application list. I think http_server is just being used for the development of exvcr and not supposed to be used projects using it.

In Elixir v1.4 you can specify that your dependency shouldn’t be added to your application list by doing:

  defp deps do
    [{:exvcr, "~> 0.8", runtime: false}]
  end

and it should fix it.

7 Likes

That fixed it!

I changed my deps to

defp deps do
  [{:exvcr, "~> 0.8", runtime: false}]
end

from

defp deps do
  [{:exvcr, "~> 0.8", only: [:test}]
end

Thank you!

1 Like

This one works for me:

{:exvcr, "~> 0.8", only: [:test], runtime: false}

1 Like