Missing Import Errors in Elixir
Elixir uses alias, import, use, and require — each with different purposes. The error (UndefinedFunctionError) function X.y/1 is undefined usually means a missing import or dependency.
alias vs import vs use
# alias — shortens module names
alias MyApp.Accounts.User
User.changeset(attrs) # Instead of MyApp.Accounts.User.changeset(attrs)
# import — brings functions into current scope
import Ecto.Query, only: [from: 2, where: 3]
from(u in User, where: u.active == true)
# use — invokes the module's __using__ macro
use GenServer # Injects GenServer callbacksMissing Dependency
If a module isn't found at all, it might be a missing dependency:
# mix.exs
defp deps do
[
{:phoenix, "~> 1.7"},
{:jason, "~> 1.4"}, # Add missing dep
]
endThen run:
mix deps.get
mix compileModule Not Compiled
If you get module X is not available, the module might have a compilation error:
mix compile --forceRequire for Macros
# Macros need require, not import
require Logger
Logger.info("This works")
# Without require:
Logger.info("This fails") # (CompileError) you must require LoggerPhoenix-Specific
# In Phoenix controllers, use brings in helpers
use MyAppWeb, :controller # Imports controller helpers
use MyAppWeb, :live_view # Imports LiveView helpersBugsly captures UndefinedFunctionError and CompileError in Elixir apps with the full module path, making it easy to trace which import is missing.
Try Bugsly Free
AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.
Get Started FreeRelated Articles
How to Fix Validation Error in Astro
Learn how to diagnose and fix Validation Error errors in Astro. Step-by-step guide with code examples.
Read moreHow to Fix Permissionerror in Laravel When Deploying
Learn how to diagnose and fix the permissionerror in Laravel when deploying. Includes code examples and prevention tips.
Read moreHow to Fix Validation Error in Flask
Fix Validation Error in your Flask app. Understand the root cause and apply the right solution.
Read moreFix Reflect Error in Angular
Step-by-step guide to fix Reflect Error in Angular. Includes root cause analysis, code examples, debugging tips, and prevention strategies.
Read more