Receiving error "Phoenix.LiveView.JS.__struct__/1 is undefined" after adding live views to Phoenix 1.6.2 application

So I generated a new project with mix phx.new my_app --no-mailer then ran mix ecto.create then mix phx.gen.live ShortLinks ShortLink short_links \ key:string \ url:text \ hit_count:integer then when trying to run mix ecto.migrate I get the following error message: == Compilation error in file lib/my_app_web/live/live_helpers.ex == ** (CompileError) lib/my_app_web/live/live_helpers.ex:55: Phoenix.LiveView.JS.__struct__/1 is undefined, cannot expand struct Phoenix.LiveView.JS. 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 lib/my_app_web/live/live_helpers.ex:55: (module). Anyone have any idea what’s going wrong here? Thank you!!!

Welcome, @amacedev! The phx.gen.live task is assuming a newer version of LiveView than what was initially installed by phx.new. Upgrading your phoenix_live_view and phoenix_live_dashboard dependencies should resolve the LiveView.JS errors.

3 Likes

Thanks so much @mcrumm! That did indeed fix the error.

2 Likes

Related Phoenix issue: Warn on phx.gen.live if LiveView.JS is missing? · Issue #4642 · phoenixframework/phoenix · GitHub

1 Like