You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Scrivener_html与Phoenix 1.6版本依赖冲突问题排查

问题描述

我希望采用offset-limit方式实现分页,因此选择了scrivener包。我的私有项目的mix.exs文件内容如下:

defp deps do
  [
    {:phoenix, "~> 1.6.10"},
    {:phoenix_ecto, "~> 4.4"},
    {:ecto_sql, "~> 3.6"},
    {:postgrex, ">= 0.0.0"},
    {:phoenix_html, "~> 3.0"},
    {:phoenix_live_reload, "~> 1.2", only: :dev},
    {:phoenix_live_view, "~> 0.17.5"},
    # {:floki, ">= 0.30.0", only: :test},
    {:phoenix_live_dashboard, "~> 0.6"},
    {:esbuild, "~> 0.4", runtime: Mix.env() == :dev},
    {:swoosh, "~> 1.3"},
    {:telemetry_metrics, "~> 0.6"},
    {:telemetry_poller, "~> 1.0"},
    {:gettext, "~> 0.18"},
    {:jason, "~> 1.2"},
    {:plug_cowboy, "~> 2.5"},
    {:nimble_csv, "~> 1.2"},
    {:iconv, "~> 1.0"},
    {:floki, "~> 0.33.0"},
    # {:html5ever, "~> 0.13.0"},
    {:fast_html, "~> 2.0"},
    {:mochiweb, "~> 3.1"},
    {:scrivener_ecto, "~> 2.0"},
    {:scrivener_html, "~> 1.8"}  #<--------- 问题出在这里
    #{:csv, "~> 2.5"}
  ]
end

执行mix deps.get时,报错信息如下:

Failed to use "phoenix" (version 1.6.14) because
  phoenix_live_reload (version 1.3.3) requires ~> 1.4
  phoenix_live_view (version 0.17.12) requires ~> 1.6.0 or ~> 1.7.0
  scrivener_html (versions 1.8.0 and 1.8.1) requires ~> 1.0 and < 1.5.0
  mix.lock specifies 1.6.14

** (Mix) Hex dependency resolution failed, change the version requirements of your dependencies or unlock them (by using mix deps.update or mix deps.unlock). If you are unable to resolve the conflicts you can try overriding with {:dependency, "~> 1.0", override: true}

但scrivener自身的mix.exs文件中,依赖信息如下,对Phoenix的要求是< 1.7:

defp deps do
  [
    {:scrivener, "~> 1.2 or ~> 2.0"},
    {:phoenix_html, "~> 2.2 or ~> 3.0"},
    {:phoenix, "~> 1.0 and < 1.7.0", optional: true},
    {:plug, "~> 1.1"},
    {:ex_doc, "~> 0.19", only: :dev},
    {:earmark, "~> 1.1", only: :dev}
  ]
end

为何会出现scrivener_html (versions 1.8.0 and 1.8.1) requires ~> 1.0 and < 1.5.0这个错误提示?


解答

你混淆了scrivener和scrivener_html两个独立的包:

  • 你查看的是scrivener的依赖要求,它确实支持Phoenix <1.7;
  • 但报错里的是scrivener_html 1.8.x版本的依赖限制,这个版本分支的代码确实要求Phoenix版本必须在~>1.0且<1.5.0范围内,和scrivener本身的依赖要求无关。

解决这个冲突的办法:

  • 升级scrivener_html到支持Phoenix 1.6的版本:scrivener_html 1.9.0及以上版本已经更新了Phoenix依赖要求,支持~>1.0 and <1.8.0,可以把依赖改成{:scrivener_html, "~> 1.9"};
  • 如果暂时不想升级,也可以使用依赖覆盖机制,在mix.exs中给scrivener_html添加override: true,但这种方式可能引发其他潜在兼容性问题,不推荐作为长期方案。

内容的提问来源于stack exchange,提问作者Chen Yu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 14:45:33