All of a sudden my app has started to crash:
$ mix phx.server
[................]
Generated my_app app
[info] Application my_app exited: MyApp.Application.start(:normal, []) returned an error: shutdown: failed to start child: MyAppWeb.Endpoint
** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
** (EXIT) an exception was raised:
** (UndefinedFunctionError) function Phoenix.Endpoint.Cowboy2Handler.child_spec/3 is undefined (module Phoenix.Endpoint.Cowboy2Handler is not available)
Phoenix.Endpoint.Cowboy2Handler.child_spec(:http, MyAppWeb.Endpoint, [port: 4000, otp_app: :my_app])
(phoenix) lib/phoenix/endpoint/handler.ex:33: anonymous fn/5 in Phoenix.Endpoint.Handler.init/1
(elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix) lib/phoenix/endpoint/handler.ex:31: Phoenix.Endpoint.Handler.init/1
(stdlib) supervisor.erl:295: :supervisor.init/1
(stdlib) gen_server.erl:374: :gen_server.init_it/2
(stdlib) gen_server.erl:342: :gen_server.init_it/6
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
** (Mix) Could not start application my_app: MyApp.Application.start(:normal, []) returned an error: shutdown: failed to start child: MyAppWeb.Endpoint
** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
** (EXIT) an exception was raised:
** (UndefinedFunctionError) function Phoenix.Endpoint.Cowboy2Handler.child_spec/3 is undefined (module Phoenix.Endpoint.Cowboy2Handler is not available)
Phoenix.Endpoint.Cowboy2Handler.child_spec(:http, MyAppWeb.Endpoint, [port: 4000, otp_app: :my_app])
(phoenix) lib/phoenix/endpoint/handler.ex:33: anonymous fn/5 in Phoenix.Endpoint.Handler.init/1
(elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix) lib/phoenix/endpoint/handler.ex:31: Phoenix.Endpoint.Handler.init/1
(stdlib) supervisor.erl:295: :supervisor.init/1
(stdlib) gen_server.erl:374: :gen_server.init_it/2
(stdlib) gen_server.erl:342: :gen_server.init_it/6
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
I'm using and have been using for a while the latest versions of everything: Cowboy - 2.5, Phoenix - 1.3. All has been working fine for over a half a year
This doesn't help
{:phoenix, github: "phoenixframework/phoenix", override: true},
Removing _build and recompiling didn't help either
It's not clear where you have phoenix locked at, given you are referencing the master branch on GitHub. Most likely you actually grabbed the 1.4 rc by updating your deps without realizing it. You can either {:phoenix, "~> 1.3"} and mix deps.update phoenix, or you can use the 1.4rc, which requires you to replace your :plug and :cowboy deps with {:plug_cowboy, "~> 2.0"}. Then` mix deps.get and you should be set. If you indeed are going the 1.4 route, also be sure to checkout the upgrade guides:
https://gist.github.com/chrismccord/bb1f8b136f5a9e4abc0bfc07b832257e
Closing as this does not appear to be an issue, but if you continue to have problems, please feel free to chime in here. Thanks!
This doesn't work either, the same error:
[
{:phoenix, "~> 1.4-rc.2", override: true},
# {:cowboy, "~> 2.4"},
{:plug_cowboy, "~> 2.0"},
There's no explicit "plug" dependency in my "mix.exs"
@naddika Could you please provide your mix.lock file or a sample project? The above configuration is working for me on a new project.
@Gazler
I've created a new HelloWorld. The error now is different.
mix.exs
defmodule Hello2.Mixfile do
use Mix.Project
def project do
[
app: :hello2,
version: "0.0.1",
elixir: "~> 1.7",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
start_permanent: Mix.env == :prod,
aliases: aliases(),
deps: deps()
]
end
# Configuration for the OTP application.
#
# Type `mix help compile.app` for more information.
def application do
[
mod: {Hello2.Application, []},
extra_applications: [:logger, :runtime_tools]
]
end
# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
# Specifies your project dependencies.
#
# Type `mix help deps` for examples and options.
defp deps do
[
{:phoenix, "~> 1.4.0-rc.2"},
{:phoenix_pubsub, "~> 1.1"},
{:phoenix_ecto, "~> 3.5"},
{:ecto, "~> 3.0-rc", override: true},
{:ecto_sql, "~> 3.0-rc", override: true},
{:postgrex, ">= 0.0.0-rc"},
{:phoenix_html, "~> 2.11"},
{:phoenix_live_reload, "~> 1.2-rc", only: :dev},
{:gettext, "~> 0.11"},
{:jason, "~> 1.0"},
{:plug_cowboy, "~> 2.0"}
]
end
# Aliases are shortcuts or tasks specific to the current project.
# For example, to create, migrate and run the seeds file at once:
#
# $ mix ecto.setup
#
# See the documentation for `Mix` for more info on aliases.
defp aliases do
[
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
"test": ["ecto.create --quiet", "ecto.migrate", "test"]
]
end
end
mix.lock
%{
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
"cowboy": {:hex, :cowboy, "2.5.0", "4ef3ae066ee10fe01ea3272edc8f024347a0d3eb95f6fbb9aed556dacbfc1337", [:rebar3], [{:cowlib, "~> 2.6.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.6.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
"cowlib": {:hex, :cowlib, "2.6.0", "8aa629f81a0fc189f261dc98a42243fa842625feea3c7ec56c48f4ccdb55490f", [:rebar3], [], "hexpm"},
"db_connection": {:hex, :db_connection, "2.0.0-rc.0", "f6960e86b5e524468ec16fb7277e509c784de565ac520213a1813ad2bf7d802f", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
"decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"},
"ecto": {:hex, :ecto, "3.0.0-rc.1", "c966a270b289739d6895f61bee339065a3075d1df34ddd369d400cf0c936fd6c", [:mix], [{:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"},
"ecto_sql": {:hex, :ecto_sql, "3.0.0-rc.0", "a61da743812a47174e8b79dbe6aa7d4a9f7e6dbf8c90cfd7015f3767738b37ba", [:mix], [{:db_connection, "~> 2.0-rc.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.0.0-rc.1", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.0-rc.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0-rc.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.2.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
"file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm"},
"gettext": {:hex, :gettext, "0.16.0", "4a7e90408cef5f1bf57c5a39e2db8c372a906031cc9b1466e963101cb927dafc", [:mix], [], "hexpm"},
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"mime": {:hex, :mime, "1.3.0", "5e8d45a39e95c650900d03f897fbf99ae04f60ab1daa4a34c7a20a5151b7a5fe", [:mix], [], "hexpm"},
"phoenix": {:hex, :phoenix, "1.4.0-rc.2", "5f9d03090a8ea9d03404a5b8610c4b9f43471a45d31cb4282f6789cdaead6f59", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm"},
"phoenix_ecto": {:hex, :phoenix_ecto, "3.5.0", "f72ec302589988698c096da7e8647e917fa2bb2f861c0c3739fc9d95708bacec", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_html": {:hex, :phoenix_html, "2.12.0", "1fb3c2e48b4b66d75564d8d63df6d53655469216d6b553e7e14ced2b46f97622", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.2.0-rc.0", "e4876fe249fdfbcca372a2c8d512a7c67d893d7a4f1bb66597050aa4d5001a69", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4-rc", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.1", "6668d787e602981f24f17a5fbb69cc98f8ab085114ebfac6cc36e10a90c8e93c", [:mix], [], "hexpm"},
"plug": {:hex, :plug, "1.7.1", "8516d565fb84a6a8b2ca722e74e2cd25ca0fc9d64f364ec9dbec09d33eb78ccd", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}], "hexpm"},
"plug_cowboy": {:hex, :plug_cowboy, "2.0.0", "ab0c92728f2ba43c544cce85f0f220d8d30fc0c90eaa1e6203683ab039655062", [:mix], [{:cowboy, "~> 2.5", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"},
"postgrex": {:hex, :postgrex, "0.14.0-rc.1", "a88cbeab25c5f3fc505fc6590bd30877a5acf11b448aedb23b41cbc063824ceb", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0-rc.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"ranch": {:hex, :ranch, "1.6.2", "6db93c78f411ee033dbb18ba8234c5574883acb9a75af0fb90a9b82ea46afa00", [:rebar3], [], "hexpm"},
"telemetry": {:hex, :telemetry, "0.2.0", "5b40caa3efe4deb30fb12d7cd8ed4f556f6d6bd15c374c2366772161311ce377", [:mix], [], "hexpm"},
}
Run it:
Generated plug app
==> phoenix_html
Compiling 8 files (.ex)
Generated phoenix_html app
==> plug_cowboy
Compiling 5 files (.ex)
Generated plug_cowboy app
==> phoenix
Compiling 67 files (.ex)
Generated phoenix app
==> phoenix_live_reload
Compiling 4 files (.ex)
Generated phoenix_live_reload app
==> phoenix_ecto
Compiling 6 files (.ex)
Generated phoenix_ecto app
warning: failed to load Poison for Phoenix JSON encoding
(module Poison is not available).
Ensure Poison is loaded from your deps in mix.exs, or
configure an existing encoder in your Mix config using:
config :phoenix, :json_library, MyJSONLibrary
(phoenix) lib/phoenix.ex:40: Phoenix.start/2
(kernel) application_master.erl:277: :application_master.start_it_old/4
==> hello2
Compiling 13 files (.ex)
warning: transport/3 in Phoenix.Socket is deprecated.
Instead of defining transports in your socket.ex file:
transport :websocket, Phoenix.Transport.Websocket,
key1: value1, key2: value2, key3: value3
transport :longpoll, Phoenix.Transport.LongPoll,
key1: value1, key2: value2, key3: value3
You should configure websocket/longpoll in your endpoint.ex:
socket "/socket", MyApp.UserSocket,
websocket: [key1: value1, key2: value2, key3: value3],
longpoll: [key1: value1, key2: value2, key3: value3]
Note the websocket/longpoll configuration given to socket/3
will only apply after you remove all transport/3 calls from
your socket definition. If you have explicitly upgraded to
Cowboy 2, any transport defined with the transport/3 macro
will be ignored.
(phoenix) lib/phoenix/socket.ex:327: Phoenix.Socket.__transport__/4
lib/hello2_web/channels/user_socket.ex:8: (module)
(elixir) src/elixir_compiler.erl:71: :elixir_compiler.dispatch/4
(elixir) src/elixir_compiler.erl:68: :elixir_compiler.compile/3
(elixir) src/elixir_module.erl:281: :elixir_module.eval_form/6
(elixir) src/elixir_module.erl:79: :elixir_module.compile/5
(stdlib) erl_eval.erl:677: :erl_eval.do_apply/6
(elixir) src/elixir.erl:265: :elixir.eval_forms/4
(elixir) src/elixir_compiler.erl:49: :elixir_compiler.eval_forms/3
(elixir) src/elixir_lexical.erl:17: :elixir_lexical.run/2
(elixir) src/elixir_compiler.erl:23: :elixir_compiler.quoted/2
(elixir) lib/kernel/parallel_compiler.ex:206: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6
warning: retrieving the :adapter from config files for Hello2.Repo is deprecated.
Instead pass the adapter configuration when defining the module:
defmodule Hello2.Repo do
use Ecto.Repo,
otp_app: :hello2,
adapter: Ecto.Adapters.Postgres
lib/ecto/repo/supervisor.ex:100: Ecto.Repo.Supervisor.deprecated_adapter/3
lib/ecto/repo/supervisor.ex:64: Ecto.Repo.Supervisor.compile_config/2
lib/hello2/repo.ex:2: (module)
(elixir) src/elixir_compiler.erl:71: :elixir_compiler.dispatch/4
(elixir) src/elixir_compiler.erl:68: :elixir_compiler.compile/3
(elixir) src/elixir_module.erl:281: :elixir_module.eval_form/6
(elixir) src/elixir_module.erl:79: :elixir_module.compile/5
(stdlib) erl_eval.erl:677: :erl_eval.do_apply/6
(elixir) src/elixir.erl:265: :elixir.eval_forms/4
(elixir) src/elixir_compiler.erl:49: :elixir_compiler.eval_forms/3
(elixir) src/elixir_lexical.erl:17: :elixir_lexical.run/2
(elixir) src/elixir_compiler.erl:23: :elixir_compiler.quoted/2
(elixir) lib/kernel/parallel_compiler.ex:206: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6
== Compilation error in file lib/hello2_web/endpoint.ex ==
** (ArgumentError) invalid :json_decoder option. The module Poison is not loaded and could not be found
(plug) lib/plug/parsers/json.ex:54: Plug.Parsers.JSON.validate_decoder!/1
(plug) lib/plug/parsers/json.ex:32: Plug.Parsers.JSON.init/1
(plug) lib/plug/parsers.ex:245: anonymous fn/3 in Plug.Parsers.convert_parsers/2
(elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
(plug) lib/plug/parsers.ex:228: Plug.Parsers.convert_parsers/2
(plug) lib/plug/parsers.ex:224: Plug.Parsers.init/1
(plug) lib/plug/builder.ex:302: Plug.Builder.init_module_plug/4
(plug) lib/plug/builder.ex:286: anonymous fn/5 in Plug.Builder.compile/3
(elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
(plug) lib/plug/builder.ex:284: Plug.Builder.compile/3
(plug) expanding macro: Plug.Builder.__before_compile__/1
lib/hello2_web/endpoint.ex:1: Hello2Web.Endpoint (module)
(elixir) lib/kernel/parallel_compiler.ex:206: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6
@naddika Have you changed the config.exs of this new project at all? Poison should only be used if this line is missing:
@Gazler no, where in the guides is that mentioned? I've haven't changed anything in the config
Also - if I don't want to use Jason?
@GildedHonour It is documented at https://hexdocs.pm/phoenix/1.4.0-rc.2/Phoenix.html#json_library/0
If you don't want to use Jason, configure it to something else.
Hi @naddika, there is something suspicious in this hello world. For example, it says elixir: "~> 1.7", but Phoenix does not generate such specification. Is it correct to assume that you have updated only some files from a new project? If so, you can fix this by either:
Poisonas a dependency in your mix.exs file: {:poison, ">= 0.0.0"}config :phoenix, :json_library, JasonThe remaining warnings can be fixed by following the instructions in the warning.
Yes, I have only Elixir 1.7 installed on my machine.
That didn't fix the error:
# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:user_id]
config :phoenix, :json_library, Jason
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env}.exs"
Did this:
$ rm -rf _build deps mix.lock && mix deps.get --all
$ mix phx.server
Still the error remained
defp deps do
[
{:phoenix, "~> 1.4.0-rc.2"},
{:phoenix_pubsub, "~> 1.1"},
{:phoenix_ecto, "~> 3.5"},
{:ecto, "~> 3.0-rc", override: true},
{:ecto_sql, "~> 3.0-rc", override: true},
{:postgrex, ">= 0.0.0-rc"},
{:phoenix_html, "~> 2.11"},
{:phoenix_live_reload, "~> 1.2-rc", only: :dev},
{:gettext, "~> 0.11"},
# {:jason, "~> 1.0"},
{:plug_cowboy, "~> 2.0"},
]
end
Can you please add {:poison, ">= 0.0.0"} to your deps? You either have to add poison and remove the jason config, or keep the jason dep and the jason config.
or keep the jason dep and the jason config. --> this is what I have.
Uncommented out jason dependency, ran rm -rf _build deps mix.lock && mix deps.get --all -- the error remains.
Why add {:poison, ">= 0.0.0"} if I'm using Jason?
@GildedHonour interesting. Can you please push to github a sample app that reproduces the error? Thank you!
With {:poison, ">= 0.0.0"} and Jason in the dependencies and Jason in the config it works
With {:poison, ">= 0.0.0"} and Jason in the dependencies and Jason in the config it works
That still implies that something is using poison, and based on your dependency list it absolutely shouldn't... So that sample project would still be useful I'd think?
@GildedHonour maybe your endpoint module (in the endpoint.ex file under your web directory) has Plug.Parsers configured with Poison as :json_decoder?
I'm having the same issue. Here's how to reproduce...
$ elixir -v
Erlang/OTP 21 [erts-10.1.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]
Elixir 1.7.4 (compiled with Erlang/OTP 21)
$ mix archive
* hex-0.18.1
* phx_new-1.4.0-rc.2
Archives installed at: /Users/cjbottaro/.mix/archives
Then...
$ mix new umbrella_ex --umbrella
$ cd umbrella_ex/apps/
$ mix phx.new.ecto foo
$ mix phx.new.web foo_web
$ cd ..
$ iex -S mix
Erlang/OTP 21 [erts-10.1.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]
warning: failed to load Poison for Phoenix JSON encoding
(module Poison is not available).
Ensure Poison is loaded from your deps in mix.exs, or
configure an existing encoder in your Mix config using:
config :phoenix, :json_library, MyJSONLibrary
(phoenix) lib/phoenix.ex:40: Phoenix.start/2
(kernel) application_master.erl:277: :application_master.start_it_old/4
==> foo_web
Compiling 11 files (.ex)
== Compilation error in file lib/foo_web/endpoint.ex ==
** (ArgumentError) invalid :json_decoder option. The module Poison is not loaded and could not be found
(plug) lib/plug/parsers/json.ex:54: Plug.Parsers.JSON.validate_decoder!/1
(plug) lib/plug/parsers/json.ex:32: Plug.Parsers.JSON.init/1
(plug) lib/plug/parsers.ex:245: anonymous fn/3 in Plug.Parsers.convert_parsers/2
(elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
(plug) lib/plug/parsers.ex:228: Plug.Parsers.convert_parsers/2
(plug) lib/plug/parsers.ex:224: Plug.Parsers.init/1
(plug) lib/plug/builder.ex:302: Plug.Builder.init_module_plug/4
(plug) lib/plug/builder.ex:286: anonymous fn/5 in Plug.Builder.compile/3
==> foo
Compiling 3 files (.ex)
Generated foo app
Thanks for the help.
Replicated it!
╰─➤ mix archive
* hex-0.18.1
* phx_new-1.4.0-rc.3
Archives installed at: /home/overminddl1/.asdf/installs/elixir/1.7.4-otp-21/.mix/archives
╰─➤ mix new umbrella_ex --umbrella
* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating apps
* creating config
* creating config/config.exs
Your umbrella project was created successfully.
Inside your project, you will find an apps/ directory
where you can create and host many apps:
cd umbrella_ex
cd apps
mix new my_app
Commands like "mix compile" and "mix test" when executed
in the umbrella project root will automatically run
for each application in the apps/ directory.
╰─➤ cd umbrella_ex/apps
╰─➤ mix phx.new.ecto foo
* creating foo/config/config.exs
* creating foo/config/dev.exs
* creating foo/config/prod.exs
* creating foo/config/prod.secret.exs
* creating foo/config/test.exs
* creating foo/lib/foo/application.ex
* creating foo/lib/foo.ex
* creating foo/test/test_helper.exs
* creating foo/README.md
* creating foo/mix.exs
* creating foo/.gitignore
* creating foo/.formatter.exs
* creating foo/lib/foo/repo.ex
* creating foo/priv/repo/seeds.exs
* creating foo/test/support/data_case.ex
* creating foo/priv/repo/migrations/.formatter.exs
Fetch and install dependencies? [Yn] y
* running mix deps.get
We are all set! Go into your application by running:
$ cd foo
Then configure your database in config/dev.exs and run:
$ mix ecto.create
You can run your app inside IEx (Interactive Elixir) as:
$ iex -S mix
╰─➤ mix phx.new.web foo_web
* creating foo_web/config/config.exs
* creating foo_web/config/dev.exs
* creating foo_web/config/prod.exs
* creating foo_web/config/prod.secret.exs
* creating foo_web/config/test.exs
* creating foo_web/lib/foo_web.ex
* creating foo_web/lib/foo_web/application.ex
* creating foo_web/lib/foo_web/channels/user_socket.ex
* creating foo_web/lib/foo_web/endpoint.ex
* creating foo_web/lib/foo_web/router.ex
* creating foo_web/lib/foo_web/views/error_helpers.ex
* creating foo_web/lib/foo_web/views/error_view.ex
* creating foo_web/mix.exs
* creating foo_web/README.md
* creating foo_web/.gitignore
* creating foo_web/test/test_helper.exs
* creating foo_web/test/support/channel_case.ex
* creating foo_web/test/support/conn_case.ex
* creating foo_web/test/foo_web/views/error_view_test.exs
* creating foo_web/.formatter.exs
* creating foo_web/lib/foo_web/gettext.ex
* creating foo_web/priv/gettext/en/LC_MESSAGES/errors.po
* creating foo_web/priv/gettext/errors.pot
* creating foo_web/lib/foo_web/controllers/page_controller.ex
* creating foo_web/lib/foo_web/templates/layout/app.html.eex
* creating foo_web/lib/foo_web/templates/page/index.html.eex
* creating foo_web/lib/foo_web/views/layout_view.ex
* creating foo_web/lib/foo_web/views/page_view.ex
* creating foo_web/test/foo_web/controllers/page_controller_test.exs
* creating foo_web/test/foo_web/views/layout_view_test.exs
* creating foo_web/test/foo_web/views/page_view_test.exs
* creating foo_web/assets/webpack.config.js
* creating foo_web/assets/.babelrc
* creating foo_web/assets/css/app.css
* creating foo_web/assets/css/phoenix.css
* creating foo_web/assets/js/app.js
* creating foo_web/assets/js/socket.js
* creating foo_web/assets/package.json
* creating foo_web/assets/static/robots.txt
* creating foo_web/assets/static/images/phoenix.png
* creating foo_web/assets/static/favicon.ico
Fetch and install dependencies? [Yn] y
* running mix deps.get
* running cd assets && npm install && node node_modules/webpack/bin/webpack.js --mode development
We are all set! Go into your application by running:
$ cd foo_web
Start your Phoenix app with:
$ mix phx.server
You can also run your app inside IEx (Interactive Elixir) as:
$ iex -S mix phx.server
╰─➤ iex -S mix
Erlang/OTP 21 [erts-10.1.1] [source] [64-bit] [smp:6:6] [ds:6:6:10] [async-threads:1] [hipe]
==> file_system
Compiling 7 files (.ex)
Generated file_system app
==> connection
Compiling 1 file (.ex)
Generated connection app
==> gettext
Compiling 1 file (.yrl)
Compiling 1 file (.erl)
Compiling 20 files (.ex)
Generated gettext app
Could not find "rebar3", which is needed to build dependency :ranch
I can install a local copy which is just used by Mix
Shall I install rebar3? (if running non-interactively, use "mix local.rebar --force") [Yn] y
* creating /home/overminddl1/.asdf/installs/elixir/1.7.4-otp-21/.mix/rebar
* creating /home/overminddl1/.asdf/installs/elixir/1.7.4-otp-21/.mix/rebar3
===> Compiling ranch
==> telemetry
Compiling 3 files (.ex)
Generated telemetry app
==> decimal
Compiling 1 file (.ex)
Generated decimal app
==> jason
Compiling 8 files (.ex)
Generated jason app
==> db_connection
Compiling 16 files (.ex)
Generated db_connection app
==> ecto
Compiling 54 files (.ex)
Generated ecto app
==> phoenix_pubsub
Compiling 13 files (.ex)
Generated phoenix_pubsub app
===> Compiling cowlib
===> Compiling cowboy
==> mime
Compiling 2 files (.ex)
Generated mime app
==> postgrex
Compiling 61 files (.ex)
Generated postgrex app
==> ecto_sql
Compiling 23 files (.ex)
Generated ecto_sql app
==> plug_crypto
Compiling 4 files (.ex)
Generated plug_crypto app
==> plug
Compiling 1 file (.erl)
Compiling 38 files (.ex)
warning: System.stacktrace/0 outside of rescue/catch clauses is deprecated. If you want to support only Elixir v1.7+, you must access __STACKTRACE__ inside a rescue/catch. If you want to support earlier Elixir versions, move System.stacktrace/0 inside a rescue/catch
lib/plug/conn/wrapper_error.ex:23
Generated plug app
==> phoenix_html
Compiling 8 files (.ex)
Generated phoenix_html app
==> plug_cowboy
Compiling 5 files (.ex)
Generated plug_cowboy app
==> phoenix
Compiling 67 files (.ex)
Generated phoenix app
==> phoenix_live_reload
Compiling 4 files (.ex)
Generated phoenix_live_reload app
==> phoenix_ecto
Compiling 6 files (.ex)
Generated phoenix_ecto app
warning: failed to load Poison for Phoenix JSON encoding
(module Poison is not available).
Ensure Poison is loaded from your deps in mix.exs, or
configure an existing encoder in your Mix config using:
config :phoenix, :json_library, MyJSONLibrary
(phoenix) lib/phoenix.ex:40: Phoenix.start/2
(kernel) application_master.erl:277: :application_master.start_it_old/4
==> foo_web
Compiling 11 files (.ex)
== Compilation error in file lib/foo_web/endpoint.ex ==
** (ArgumentError) invalid :json_decoder option. The module Poison is not loaded and could not be found
(plug) lib/plug/parsers/json.ex:54: Plug.Parsers.JSON.validate_decoder!/1
(plug) lib/plug/parsers/json.ex:32: Plug.Parsers.JSON.init/1
(plug) lib/plug/parsers.ex:245: anonymous fn/3 in Plug.Parsers.convert_parsers/2
(elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
(plug) lib/plug/parsers.ex:228: Plug.Parsers.convert_parsers/2
(plug) lib/plug/parsers.ex:224: Plug.Parsers.init/1
(plug) lib/plug/builder.ex:302: Plug.Builder.init_module_plug/4
(plug) lib/plug/builder.ex:286: anonymous fn/5 in Plug.Builder.compile/3
==> foo
Compiling 3 files (.ex)
Generated foo app
And plug is indeed {:plug_cowboy, "~> 2.0"}.
Thus I confirm new instance oddity! Thanks for the exact reproducible steps!
And adding config :phoenix, :json_library, Jason to the web's config.exs fixed it. It looks like Phoenix is still defaulting to Poison, which is especially bad because I think Poison v4 changed it's API.
The only calling of Poison that I can find is:
./deps/phoenix/lib/phoenix.ex: Application.get_env(:phoenix, :json_library, Poison)
So yes, it looks like Phoenix is still defaulting to Poison for some reason!
@chrismccord ^
Is it appropriate to just add it to the template or should the default in Phoenix itself be changed since I keep hearing that Poison's latest API changed things too much to work?
We cannot default to Jason since it would be a breaking change for existing applications. So 1.4 apps are explicitly configured for Jason, allowing us to promote Jason going forward, but existing users Poison ~> 3.0 will continue to work.
So 1.4 apps are explicitly configured for Jason, allowing us to promote Jason going forward, but existing users Poison ~> 3.0 will continue to work.
I can easily see (as per the forums lately) someone adding Poison v4 to a project after seeing the message that Poison is missing, what about a better error message if the API is not appropriate for the passed in Module atom via a compile-time round-trip JSON test or so using the needed API's?
Phoenix does restrict itself to Poison ~> 3.0, so if someone wants to override that, it is their own risk to take.
We cannot default to Jason since it would be a breaking change for existing applications.
I think this is what a major release is about. And if someone really depends on a obsolete library, there is still config :phoenix, :json_library, Poison.
Oh my bad, 1.3 -> 1.4 is actually a minor release.. But it somehow feels like a major. :D