0

我正在使用一个名为erlang_decimal的 erlang 库来做一些十进制数学运算。我的应用程序还使用Decimal作为 Ecto 的子依赖项,Ecto 是基本相同类型的 Elixir 库。

这是我的mix.exs

  defp deps do
    [
      {:bcrypt_elixir, "~> 1.0"},
      {:comeonin, "~> 4.0"},
      {:configparser_ex, "~> 2.0"},
      {:csv, "~> 2.1.1"},
      {:decimal, "~> 1.0},
      {:ecto_enum, "~> 1.0"},
      {:ecto_sql, "~> 3.0"},
      {:erlang_decimal, "~> 0.4", app: false},
      {:ex_aws, "~> 2.0"},
      {:ex_aws_s3, "~> 2.0"},
      {:ex_machina, "~> 2.2", only: [:dev, :test]},
      {:ex_twilio, "~> 0.6.0"},
      {:gettext, "~> 0.11"},
      {:httpoison, "~> 1.0"},
      {:jason, "~> 1.0"},
      {:phoenix, "~> 1.4.0"},
      {:phoenix_ecto, "~> 4.0"},
      {:phoenix_html, "~> 2.10"},
      {:phoenix_live_reload, "~> 1.0", only: :dev},
      {:phoenix_pubsub, "~> 1.0"},
      {:plug, "~> 1.7"},
      {:plug_cowboy, "~> 2.0"},
      {:postgrex, ">= 0.0.0"},
      {:ranch, "~> 1.3"},
      {:sentry, "~> 7.0"},
      {:signed_overpunch, "~> 0.2"},
      {:sweet_xml, "~> 0.6"},
      {:telcom_parser, in_umbrella: true},
      {:timex, github: "bitwalker/timex", ref: "74afe810ee9c8e58e057830e62a865230ce00133"},
      {:trixie, in_umbrella: true}
    ]
  end

部署更改后,我遇到了以下异常:

  Elixir.UndefinedFunctionError: function Decimal.new/3 is undefined (module Decimal is not available)
    Module "Elixir.Decimal", in Decimal.new/3
    File "lib/postgrex/type_module.ex", line 713, in Postgrex.DefaultTypes."Elixir.Postgrex.Extensions.Numeric"/6
    File "lib/postgrex/protocol.ex", line 2733, in Postgrex.Protocol.rows_recv/4
    File "lib/postgrex/protocol.ex", line 1777, in Postgrex.Protocol.recv_execute/5
    File "lib/postgrex/protocol.ex", line 1652, in Postgrex.Protocol.bind_execute/4
    File "lib/db_connection/holder.ex", line 268, in DBConnection.Holder.holder_apply/4
    File "lib/db_connection.ex", line 1189, in DBConnection.run_execute/5
    File "lib/db_connection.ex", line 1276, in DBConnection.run/6
    Module "erlang", in :erlang.apply/2

是否存在某种命名空间冲突?

编辑:

Dialyzer 能够解决这个问题:

Total errors: 6, Skipped: 0
done in 0m5.83s
:0:unknown_function
Function Decimal.compare/2 does not exist.
________________________________________________________________________________
:0:unknown_function
Function Decimal.div/2 does not exist.
________________________________________________________________________________
:0:unknown_function
Function Decimal.mult/2 does not exist.
________________________________________________________________________________
:0:unknown_function
Function Decimal.new/1 does not exist.
________________________________________________________________________________
:0:unknown_function
Function Decimal.round/3 does not exist.
________________________________________________________________________________
:0:unknown_function
Function Decimal.to_integer/1 does not exist.
________________________________________________________________________________
done (warnings were emitted)

我更新了mix.exs包括{:decimal, "~> 1.0"}

4

1 回答 1

2

根据您链接的十进制文档:

在 mix.exs 文件中添加 Decimal 作为依赖项。

def deps do
  [{:decimal, "~> 1.0"}]
end

但是,您发布的 mix.exs 文件并未指定该依赖项。此外,错误消息说:

(模块 Decimal 不可用)

这也表明您需要将 Decimal 模块添加到您的应用程序中。

==========

在努力erlang_decimal工作之后,我尝试向 mix.exs 添加另一个依赖项:

 defp deps do
    [
      {:decimal, "~> 0.4.3", hex: :erlang_decimal},
      {:decimal, "~> 1.6"}

    ]

结果是这样的:

混合 deps.get 警告:依赖项:decimal 在顶层重复,请删除其中之一

在 mix.exs: {:decimal, "~> 0.4.3", [env: :prod, repo: "hexpm", hex: "erlang_decimal"]}

在 mix.exs: {:decimal, "~> 1.6", [env: :prod, repo: "hexpm", hex: "decimal"]}

确保它们匹配或在您的部门中指定上述之一并设置“覆盖:真”**(混合)由于依赖项错误而无法继续

然后看:

https://elixirforum.com/t/how-can-i-specify-multiple-dependencies-that-have-the-same-name/926

和:

https://elixirforum.com/t/working-with-modules-with-same-name/11364/6

于 2019-01-22T02:36:40.477 回答