【问题标题】:mix deps error when 2 libraries share the same dependancy and require different versions当 2 个库共享相同的依赖项并需要不同的版本时,混合 deps 错误
【发布时间】:2019-07-31 13:25:58
【问题描述】:

我在解决我的 phoenix 应用程序的依赖项时遇到问题:

我的 mix.exs 文件有:

{:phoenix, "~> 1.4.0"},
{:phoenix_pubsub, "~> 1.1"},
{:phoenix_ecto, "~> 4.0"},
{:ecto_sql, "~> 3.0"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.11"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:gettext, "~> 0.11"},
{:jason, "~> 1.0"},
{:plug_cowboy, "~> 2.0"},
{:redix, ">= 0.0.0"},
{:extwitter, "~> 0.9.3"},      
{:timex, "~> 3.0"},
{:corsica, "~> 1.0"},
{:cachex, "~> 3.1"},
{:bamboo, "~> 1.1"},
{:bamboo_ses, "~> 0.1.0"},
{:comeonin, "~> 4.1"},
{:bcrypt_elixir, "~> 1.1"},
{:ex_machina, "~> 2.2", only: :test}

I then added this stripe library:

 {:stripity_stripe, "~> 2.0.0"},

现在,当我执行 deps.get 时,我看到了这个错误:

未能使用“hackney”(版本 1.13.0 到 1.15.1),因为竹子 (版本 1.1.0 和 1.2.0)需要 >= 1.13.0 stripity_stripe (版本 2.0.0 和 2.0.1)需要 ~> 1.12.1

** (Mix) Hex 依赖解析失败,更改依赖的版本要求或解锁它们(通过使用 mix deps.update 或混合 deps.unlock)。如果您无法解决 冲突你可以尝试用 {:dependency, "~> 1.0", 覆盖:真}

我已经这样做了:

mix clean
rm mix.lock
mix deps.get

如何使用该覆盖选项?如果 2 个库需要不同版本的共享依赖项,这将如何工作?

【问题讨论】:

    标签: elixir phoenix-framework


    【解决方案1】:

    如果可能的话,在你的场景中你可以使用

    {:stripity_stripe, "~> 2.2.2"}
    

    或者您应该能够将 hackney 添加为依赖项并应用 override: true

    {:hackney, "~> 1.13", override: true}
    

    希望有帮助

    【讨论】:

      【解决方案2】:

      我找到了similar question on the elixir forum。相关引述:

      您不能同时运行同一应用程序的多个版本

      单个模块只能存在于 VM 上的一个版本中。因此,这对应用程序结构进行了限制。这基本上意味着每个人都需要就一个版本达成一致。

      另外,the docs for :override 状态:

      如果设置为true,则依赖项将覆盖其他依赖项对其自身的任何其他定义

      这听起来不像您想要的,因为您只会强制 stripity_stripe 2.0.0 使用与预期不同的版本。

      您似乎需要找到一个依赖于hackney 版本的stripity_stripe 版本,而:bamboo, "~> 1.1" 也支持该版本。

      所以,

      {:bamboo, "~> 1.1"},
      {:stripity_stripe, "~> 2.2.2"}
      

      看起来不错。我用mix deps.get对此进行了测试,结果很好。

      【讨论】:

        猜你喜欢
        • 2011-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-11
        • 2023-04-01
        相关资源
        最近更新 更多