dubesoftware

dubesoftware

Hi all,

I’m taking the Elixir/OTP course over at Developing With Elixir/OTP (Pragmatic Studio). When I run my file with elixir <path-to-file> all is well. However, I defined a module and ran iex -S mix and after that, the compiler throws errors saying the module cannot be imported. I rolled the code back and the error persists. I deleted the _build directory with no success. The module is defined in plugins.ex as follows:

defmodule Servy.Plugins do
  import Logger

  def rewrite_path(%{path: "/wildlife"} = conv) do
      %{ conv | path: "/wildthings" }
  end

  def rewrite_path(%{path: path} = conv) do
      regex = ~r{\/(?<thing>\w+)\?id=(?<id>\d+)}
      captures = Regex.named_captures(regex, path)
      rewrite_path_captures(conv, captures)
  end

  def rewrite_path(conv), do: conv

  def rewrite_path_captures(conv, %{"thing" => thing, "id" => id}) do
      %{ conv | path: "/#{thing}/#{id}" }
  end

  def rewrite_path_captures(conv, nil), do: conv

  def log(conv) do
      Logger.info "Inspecting conversation map..."
      IO.inspect conv
  end

  def track(%{status: 404, path: path} = conv) do
      IO.puts "Warning: #{path} is on the loose!"
      conv
  end

  def track(conv), do: conv
end

and it is imported in handler.ex as follows:

defmodule Servy.Handler do
	@moduledoc "Handles HTTP requests."

  @pages_path Path.expand("../../pages", __DIR__)

  import Servy.Plugins, only: [rewrite_path: 1, log: 1, track: 1]
...

Any ideas what’s going on?

TIA.

Showing Posts 1 to 3

dubesoftware

dubesoftware OP

Update: when I run rm -rf _build in my project home directory, and then I run iex -S mix, the app is recompiled successfully and I can import all modules in iex. However, running a standalone file using elixir path/to/file still produces the error “** (CompileError) lib/servy/handler.ex:6: module Servy.Plugins is not loaded and could not be found”

Any ideas as to what’s going on?

ericmj

ericmj

Elixir Core Team

You shouldn’t execute files as scripts using elixir when you are inside a mix project. mix has all the context of your project files and will automatically compile and load the files in it, elixir on the other hand only knows about the files you pass to it directly on the command line, that’s why it cannot find the Servy.Plugins module.

To run the code inside your project you should use iex -S mix like you already do or using the mix run task.

dubesoftware

dubesoftware OP

Thank you, this did solve the issue. I also double-checked the video lesson and found a rather similar explanation.

I’m glad that this turned out to be a PEBKAC and not worse.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Hellowman
Hello everyone! I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++. Does anyone ...
New
yarrichar
I’m very new to Elixir, so sorry if this is a silly question: I am wondering what happens to the mailbox of a process when the machine i...
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
Fl4m3Ph03n1x
Background When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error: * assembling mark...
New
mandar1045
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
rlipscombe
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
saleyn
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews