[英]Elixir Decimal and :erlang_decimal
我正在使用一個名為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"}
根據您鏈接的十進制文檔:
在您的mix.exs文件中將Decimal添加為依賴項。
def deps do [{:decimal, "~> 1.0"}] end
但是,您發布的mix.exs文件沒有指定該依賴性。 此外,錯誤消息顯示:
(模塊十進制不可用)
這還表明您需要將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”,十六進制:“ erlang_decimal”]}
在mix.exs中:{:decimal,“〜> 1.6”,[env::prod,repo:“ hexpm”,hex:“ decimal”]}
確保它們匹配或在您的部門中指定上述之一,並設置為“ override:true”。**(混合)由於依賴項錯誤而無法繼續
然后看:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.