安装 Phoenix Live Dashboard 后出现未定义函数错误

Undefined Function Error after installing Phoenix Live Dashboard

我在尝试使用 Phoenix Live 仪表板时遇到此错误

[2022-04-27 10:15:55.423][][error] #PID<0.4393.0> running gerardWeb.Endpoint (connection #PID<0.4388.0>, stream id 2) terminated
Server: localhost:4000 (http)
Request: GET /dashboard/home
** (exit) an exception was raised:
    ** (UndefinedFunctionError) function Phoenix.HTML.attributes_escape/1 is undefined or private
        (phoenix_html) Phoenix.HTML.attributes_escape([{{:safe, "data-page"}, :home}])
        (phoenix_live_dashboard) lib/phoenix/live_dashboard/page_live.ex:3: anonymous fn/2 in Phoenix.LiveDashboard.PageLive.render/1
        (phoenix_live_view) lib/phoenix_live_view/diff.ex:387: Phoenix.LiveView.Diff.traverse/7
        (phoenix_live_view) lib/phoenix_live_view/diff.ex:494: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
        (elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
        (phoenix_live_view) lib/phoenix_live_view/diff.ex:387: Phoenix.LiveView.Diff.traverse/7
        (phoenix_live_view) lib/phoenix_live_view/diff.ex:138: Phoenix.LiveView.Diff.render/3
        (phoenix_live_view) lib/phoenix_live_view/static.ex:244: Phoenix.LiveView.Static.to_rendered_content_tag/4
        (phoenix_live_view) lib/phoenix_live_view/static.ex:126: Phoenix.LiveView.Static.render/3
        (phoenix_live_view) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
        (phoenix) lib/phoenix/router.ex:355: Phoenix.Router.__call__/2
        (gerard) lib/plug/error_handler.ex:80: gerardWeb.Router.call/2
        (gerard) lib/gerard_web/endpoint.ex:1: gerardWeb.Endpoint.plug_builder_call/2
        (gerard) lib/plug/debugger.ex:136: gerardWeb.Endpoint."call (overridable 3)"/2
        (gerard) lib/gerard_web/endpoint.ex:1: gerardWeb.Endpoint.call/2
        (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:54: Phoenix.Endpoint.Cowboy2Handler.init/4
        (cowboy) /home/txhgkl/Documents/blink/gerard/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
        (cowboy) /home/txhgkl/Documents/blink/gerard/deps/cowboy/src/cowboy_stream_h.erl:300: :cowboy_stream_h.execute/3
        (cowboy) /home/txhgkl/Documents/blink/gerard/deps/cowboy/src/cowboy_stream_h.erl:291: :cowboy_stream_h.request_process/3
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/

我的依赖项如下所示:

{:ecto_sql, "~> 3.6.2"},      
{:phoenix, "~> 1.6.0"},
{:phoenix_live_view, "~> 0.17.7"},
{:phoenix_html, "~> 2.9", override: true},
{:phoenix_pubsub, "~> 2.0"},
{:phoenix_live_dashboard, "~> 0.6.5", override: true},
{:postgrex, "~> 0.15"},

我已经尝试将 phoenix_live_dashboard 降级为 0.50.4,同样的问题再次发生

第一个包含 Phoenix.HTML.attributes_escape/1 定义的 phoenix_html 版本是 3.1.0,但您用 {:phoenix_html, "~> 2.9", override: true} 强行覆盖依赖关系以使用旧版本。

删除 override: true 选项并指定至少 "~> 3.1" 的版本(在撰写本文时,3.2.0 是最新的可用版本)。如果你有一个收敛的依赖解决问题,你可以更新旧的依赖,期望旧的 2.9.x 版本或者将覆盖选项放回原处并测试以确保新版本没有任何变化这会破坏您的应用程序。

此函数的文档是 available on hexdocs,您可以观察到,如果将 hexdocs 切换到 v2.9.x,则该函数未定义。