All posts

Fix Missing Import in Elixir

Resolve module and function import errors in Elixir projects, covering alias, import, use directives, and Mix dependency issues.

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 callbacks

Missing 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
  ]
end

Then run:

mix deps.get
mix compile

Module Not Compiled

If you get module X is not available, the module might have a compilation error:

mix compile --force

Require for Macros

# Macros need require, not import
require Logger
Logger.info("This works")

# Without require:
Logger.info("This fails")  # (CompileError) you must require Logger

Phoenix-Specific

# In Phoenix controllers, use brings in helpers
use MyAppWeb, :controller  # Imports controller helpers
use MyAppWeb, :live_view    # Imports LiveView helpers

Bugsly 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 Free