Compilation error when running ecto.migrate after import of phx.gen.auth

OK great - that form/1 comes from Phoenix.LiveView.Helpers. So let’s make sure that is being properly imported. The first step is to the View:

# lib/testproject_web/views/user_confirmation_view.ex
defmodule TestprojectWeb.UserConfirmationView do
  use TestprojectWeb, :view
end

This tells us where the imports are being defined - in TestprojectWeb.view. So let’s check that out:

# lib/testproject_web.ex
defmodule TestprojectWeb do
  ...
  def view do
    quote do
      use Phoenix.View,
        root: "lib/testproject_web/templates",
        namespace: TestprojectWeb

      # Import convenience functions from controllers
      import Phoenix.Controller,
        only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1]

      # Include shared imports and aliases for views
      unquote(view_helpers())
    end
  end
  ...
end

The very last part is what we’re looking for - the shared imports. But that comes from yet another function called view_helpers, which is here in the same file. Scroll down further and you should find

# lib/testproject_web.ex
defp view_helpers do
  quote do
    # Use all HTML functionality (forms, tags, etc)
    use Phoenix.HTML

    # Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc)
    import Phoenix.LiveView.Helpers

    # Import basic rendering functionality (render, render_layout, etc)
    import Phoenix.View

    import TestprojectWeb.ErrorHelpers
    import TestprojectWeb.Gettext
    alias TestprojectWeb.Router.Helpers, as: Routes
  end
end

And there is Phoenix.LiveView.Helpers being imported! Note the comment even mentions the <.form> helper included.

Hopefully at some point in this process, you found something was missing, and could use the examples above to remedy the issue. If not - if everything is already there, and you’re still getting the missing form/1 error - then we can try some other possibilities next.

6 Likes