elixir-maru / maru

Elixir RESTful Framework
https://maru.readme.io
BSD 3-Clause "New" or "Revised" License
1.32k stars 85 forks source link

** (Mix) Could not start application ranch: could not find application file: ranch.app #110

Closed moxley closed 6 years ago

moxley commented 6 years ago

Following the guide at https://maru.readme.io/docs/basic-usage

$ elixir --version
Erlang/OTP 21 [erts-10.0.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]

Elixir 1.6.5 (compiled with OTP 21)

$ mix new my_app
* creating README.md
* creating .formatter.exs
defmodule MyApp.MixProject do
* creating .gitignore
* creating mix.exs
* creating config
* creating config/config.exs
* creating lib
* creating lib/my_app.ex
* creating test
* creating test/test_helper.exs
* creating test/my_app_test.exs

Your Mix project was created successfully.
You can use "mix" to compile it, test it, and more:

    cd my_app
    mix test

Run "mix help" for more commands.
$ cd my_app
$ git init
Initialized empty Git repository in /Users/mstratton/work/my_app/.git/
(master #) $ git add .
(master #) $ git ci -m "initial commit"
[master (root-commit) 82bc18d] initial commit
 8 files changed, 134 insertions(+)
 create mode 100644 .formatter.exs
 create mode 100644 .gitignore
 create mode 100644 README.md
 create mode 100644 config/config.exs
 create mode 100644 lib/my_app.ex
 create mode 100644 mix.exs
 create mode 100644 test/my_app_test.exs
 create mode 100644 test/test_helper.exs
(master) $ vi mix.exs
(master *) $ git diff
diff --git a/mix.exs b/mix.exs
index 4546afe..d63a056 100644
--- a/mix.exs
+++ b/mix.exs
@@ -21,8 +21,7 @@ defmodule MyApp.MixProject do
   # Run "mix help deps" to learn about dependencies.
   defp deps do
     [
# This file is responsible for configuring your application
-      # {:dep_from_hexpm, "~> 0.3.0"},
-      # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
+      {:maru, "~> 0.11"}
     ]
   end
 end
(master *) $ cat > lib/router.ex
  defmodule MyAPP.Router.Homepage do
    use Maru.Router

    get do
      json(conn, %{ hello: :world })
    end
  end

  defmodule MyAPP.API do
    use Maru.Router

    plug Plug.Parsers,
      pass: ["*/*"],
      json_decoder: Poison,
      parsers: [:urlencoded, :json, :multipart]

    mount MyAPP.Router.Homepage

    rescue_from :all do
      conn
      |> put_status(500)
      |> text("Server Error")
    end
  end
(master *) $ vi config/config.exs
(master *) $ git diff config/config.exs
diff --git a/config/config.exs b/config/config.exs
index d7c2d81..3df200e 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -21,6 +21,9 @@ use Mix.Config
 #     config :logger, level: :info
 #

+config :maru, MyAPP.API,
+  http: [port: 8880]
+
 # It is also possible to import configuration files, relative to this
 # directory. For example, you can emulate configuration per environment
 # by uncommenting the line below and defining dev.exs, test.exs and such.
(master *) $ mix deps.get
Resolving Hex dependencies...
Dependency resolution completed:
New:
  maru 0.13.2
  mime 1.3.0
  plug 1.6.3
* Getting maru (Hex package)
* Getting plug (Hex package)
* Getting mime (Hex package)
(master *) $ iex -S mix
Erlang/OTP 21 [erts-10.0.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]

==> mime
Compiling 2 files (.ex)
Generated mime app
==> plug
Compiling 1 file (.erl)
Compiling 48 files (.ex)
Generated plug app
==> maru
Compiling 58 files (.ex)

12:38:22.805 [warn]  Json library Elixir.Jason is not loaded, add your json library to deps and config with `config :maru, :json_library, Elixir.Jason`
warning: function Jason.decode!/1 is undefined (module Jason is not available)
  lib/maru/test.ex:99

Generated maru app
==> my_app
Compiling 2 files (.ex)
Generated my_app app
=INFO REPORT==== 21-Sep-2018::12:38:23.707060 ===
    application: logger
    exited: stopped
    type: temporary
** (Mix) Could not start application ranch: could not find application file: ranch.app

The solution the resolve the above error appears to be to add cowboy and ranch as dependencies:

   defp deps do
     [
      {:cowboy, "~> 2.4"},
      {:maru, "~> 0.11"},
      {:ranch, "~> 1.5"}
     ]
   end

Additionally, the specific versions had to be tweaked to get working. The latest version of ranch is not compatible with the latest version of cowboy, so I downgraded ranch from 1.6 to 1.5.

Resolving the dependencies did not get me to a working application. Another issue covers that: #111

moxley commented 6 years ago

Alternately, I tried specifying the latest release of maru and the latest of cowboy:

  defp deps do
    [
      {:cowboy, "~> 2.4"},
      {:maru, "~> 0.13"}
    ]
  end

That resolved the need to specify ranch, but it still ended up with the issue in #111.