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.
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
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
- #blog-post
- #ai
- #phoenix_html
- #iex
- #elixirconf-us
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dubesoftware
Update: when I run
rm -rf _buildin my project home directory, and then I runiex -S mix, the app is recompiled successfully and I can import all modules iniex. However, running a standalone file usingelixir path/to/filestill 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
You shouldn’t execute files as scripts using
elixirwhen you are inside a mix project.mixhas all the context of your project files and will automatically compile and load the files in it,elixiron the other hand only knows about the files you pass to it directly on the command line, that’s why it cannot find theServy.Pluginsmodule.To run the code inside your project you should use
iex -S mixlike you already do or using themix runtask.dubesoftware
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.