APB9785
Live Components suddenly not compiling, app crashing with UndefinedFunctionError
I’ve been re-arranging my code to break a larger LiveView app into smaller Live Components based on separation of concerns. In the main app I alias the component module name (BoardComponent), then render:
<%= live_component @socket, BoardComponent,
active_user: @active_user,
user_cache: @user_cache,
active_board: @active_board %>
I’ve done this with several different components so far, with no problems. But after doing a little work today, I’m suddenly getting hit with
** (UndefinedFunctionError) function MyAppWeb.BoardComponent.__live__/0 is undefined (module MyAppWeb.BoardComponent is not available)
But not just for the BoardComponent… when I try to access a different one - same exact error:
** (UndefinedFunctionError) function MyAppWeb.PostComponent.__live__/0 is undefined (module MyAppWeb.PostComponent is not available)
Even components that were not even touched by today’s work, for some reason are “not available”. And it’s really strange.. After reloading and recompiling a few times, I can get some modules to work but not others… and I’m not changing the code AT ALL - just killing and restarting mix phx.server gives different results each time.
Any ideas what could be going on? I didn’t really make any major changes today.
Marked As Solved
Also Liked
azyzz228
I got the same message. Figured out the issue has to do with code editor. When I was adding route for liveview, my code editor (VSCode with elixir extensions) suggested modules (one of which is my LiveView module), then I click “enter” on it and code editor automatically imports alias MyApp.MyLiveViewComponent which basically screws up everything. then I go and delete the import, and voila, error is gone
APB9785
I fixed my own issue by making non-changes
e.g. {:ok, socket} to:
{:ok,
socket
}
doing that one-by-one for all my components, and Elixir then recompiled the files and now there are no errors. Even if I revert the changes back to {:ok, socket} it still works. Very strange…
Exadra37
Did you by any chance compiled the code or ran the app with different versions of Elixir:
- like be trying out the app inside a docker container with the entire project mapped as a volume?
- or by using your software version manager tool, like
asdfto run the app with different Elixir version?
If you have done this then the _build folder get’s itself in a weird state. Also when trying out new versions of Elixir you may end-up with incompatible versions in your mix.lock and deps folder.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









