LiveView Error

Hello, I set up my project for using LiveView, added those modifications to SpareWeb.ex

def view do
    quote do
      use Phoenix.View,
        root: "lib/spare_web/templates",
        namespace: SpareWeb
      # Import convenience functions from controllers
      import Phoenix.Controller, only: [get_flash: 1, get_flash: 2, view_module: 1]
      import Phoenix.LiveView, only: [live_render: 2, live_render: 3]
      # Use all HTML functionality (forms, tags, etc)
      use Phoenix.HTML

      import SpareWeb.ErrorHelpers
      import SpareWeb.Gettext
      alias SpareWeb.Router.Helpers, as: Routes

But whenever I run mix phx.server I get the following error:

** (CompileError) lib/spare_web/views/layout_view.ex:2: cannot import Phoenix.LiveView.live_render/2 because it is undefined or private
    (elixir) src/elixir_import.erl:78: :elixir_import.calculate/6
    (elixir) src/elixir_import.erl:18: :elixir_import.import/4
    expanding macro: SpareWeb.__using__/1
    lib/spare_web/views/layout_view.ex:2: SpareWeb.LayoutView (module)
    (elixir) expanding macro: Kernel.use/2
    lib/spare_web/views/layout_view.ex:2: SpareWeb.LayoutView (module)
    (elixir) lib/kernel/parallel_compiler.ex:229: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7

Any help?
Thanks in advance!

It appears that only live_render/3 exists. You can fix it by changing your code like this:

- import Phoenix.LiveView, only: [live_render: 2, live_render: 3]
+ import Phoenix.LiveView, only: [live_render: 3]

1 Like

This changed in LiveView 0.5.0:

Phoenix.LiveView no longer defined live_render and live_link. These functions have been moved to Phoenix.LiveView.Helpers which can now be fully imported in your views. In other words, replace import Phoenix.LiveView, only: [live_render: …, live_link: …] by import Phoenix.LiveView.Helpers

from the CHANGELOG

Add this to your view macro:

- import Phoenix.LiveView, only: [live_render: 2, live_render: 3]
+ import Phoenix.LiveView.Helpers