Added authentication to a Phoenix 1.7 app using phx.gen.auth, now doesn't compile

Situation:
Phoenix 1.7.2 project (started life as 1.6) using LiveView 0.18.18, all working OK

Ran mix phx.gen.auth Accounts User users to experiment with authentication.

Now compilation fails with 20+ errors like this:

error: undefined function button/1 (expected MyappWeb.UserConfirmationInstructionsLive to define such a function or for it to be imported, but none are available)
  lib/myapp_web/live/user_confirmation_instructions_live.ex:8: MyappWeb.UserConfirmationInstructionsLive.render/1

error: undefined function header/1 (expected MyappWeb.UserConfirmationInstructionsLive to define such a function or for it to be imported, but none are available)
  lib/myapp_web/live/user_confirmation_instructions_live.ex:8: MyappWeb.UserConfirmationInstructionsLive.render/1
.
.

This sounds like an issue others have had, due to the change from Phoenix.View to Phoenix.Template in 1.7. But is there an easy-to-understand guide how to alter the generated code to make it work? I’ve looked at the other posts and answers around this issue in this forum but wasn’t able to work out exactly what to change and in what files to make things work.

Any help would be greatly appreciated.

Copy the CoreComponents module from a Phoenix 1.7 project and import it.

1 Like

Thanks for the reply.

But import the copied module into where exactly? (apologies for my ignorance)

If you generate a new Phoenix app using the latest generators, it’d go under lib/my_app_web/components/core_components.ex. That said, it should work regardless of where it is in the directory structure so long as it’s properly imported.

Following Phoenix conventions, that means making sure that your MyAppWeb module located in lib/my_app_web.ex includes import MyAppWeb.CoreComponents within view_helpers/0 or html_helpers/0 depending on when your Phoenix app was first generated or last refactored.

1 Like

Thanks so much @cschmatzler and @codeanpeace, your suggestions solved the problem. I had to add html and html_helper functions to myapp_web.ex also, but that was straightforward.

Thanks so much for your help, it is very much appreciated.

I am into same problem, I tried copying the core components from another project but core_component.ex is not running due to version conficts of phoenix_html and phoenix_live_view. Any idea how can I solve this?

error: Phoenix.HTML.FormField.struct/0 is undefined, cannot expand struct Phoenix.HTML.FormField. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code

295 │ def input(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do
│ ^

└─ lib/manage_bond_web/components.ex:295:22: ManageBondWeb.Components.input/1