0

我在 elixir 1.9 中的函数解码来自外部 api 的 json 响应,如下所示:

def decode({ok, body, "application/json"}) when is_binary(body) do
    body
    |> Poison.decode(keys: :atoms)
    |> case do
       {:ok, parsed} -> {ok, parsed}
       _ -> {:error, body}
     end 
end

它在开发中运行良好,但应用程序崩溃并显示以下错误消息:

 ** (EXIT) an exception was raised:
    ** (UndefinedFunctionError) function Poison.decode/2 is undefined (module Poison is not available)

这是我的 mix.ex,其中包含了依赖项:

defp deps do
 [
  # {:dep_from_hexpm, "~> 0.3.0"},
  # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
  { :credo, "~> 0.4", only: [:dev, :test] },
  { :httpoison, "~> 1.6" },
  { :plug_cowboy, "~> 2.0" },
  { :poison, "~> 3.1" },
  { :plug_logger_json, "~> 0.7.0" },
  { :stash, "~> 1.0.0" },
  {:edeliver, ">= 1.6.0"},
  {:distillery, "~> 2.0", warn_missing: false},
  ]
end

这就是我编译生产版本的方式:

 MIX_ENV=prod mix deps.clean --all 
 && MIX_ENV=prod mix deps.get 
 && MIX_ENV=prod mix clean 
 && MIX_ENV=prod mix compile 
 && MIX_ENV=prod mix release my_app

mix.exs 应用程序/0

  def application do
    [
      applications: [:plug_logger_json, :httpoison, :edeliver],
      extra_applications: [:logger, :plug_cowboy],
      mod: {My.Application, []}
    ]
  end

您的帮助将不胜感激。

4

0 回答 0